19
19
use 5.008;
20
20
use strict;
21
21
use warnings $ENV {GIT_PERL_FATAL_WARNINGS } ? qw( FATAL all) : ();
22
- use POSIX qw/ strftime/ ;
23
- use Term::ReadLine;
24
22
use Getopt::Long;
25
- use Text::ParseWords;
26
- use Term::ANSIColor;
27
- use File::Temp qw/ tempdir tempfile / ;
28
- use File::Spec::Functions qw( catdir catfile) ;
29
23
use Git::LoadCPAN::Error qw( :try) ;
30
- use Cwd qw( abs_path cwd) ;
31
24
use Git;
32
25
use Git::I18N;
33
- use Net::Domain ();
34
- use Net::SMTP ();
35
- use Git::LoadCPAN::Mail::Address;
36
26
37
27
Getopt::Long::Configure qw/ pass_through / ;
38
28
@@ -166,7 +156,6 @@ sub format_2822_time {
166
156
);
167
157
}
168
158
169
- my $have_email_valid = eval { require Email::Valid; 1 };
170
159
my $smtp ;
171
160
my $auth ;
172
161
my $num_sent = 0;
@@ -192,14 +181,6 @@ sub format_2822_time {
192
181
193
182
my $repo = eval { Git-> repository() };
194
183
my @repo = $repo ? ($repo ) : ();
195
- my $term = eval {
196
- $ENV {" GIT_SEND_EMAIL_NOTTY" }
197
- ? Term::ReadLine-> new(' git-send-email' , \*STDIN , \*STDOUT )
198
- : Term::ReadLine-> new(' git-send-email' );
199
- };
200
- if ($@ ) {
201
- $term = FakeTerm-> new(" $@ : going non-interactive" );
202
- }
203
184
204
185
# Behavior modification variables
205
186
my ($quiet , $dry_run ) = (0, 0);
@@ -319,9 +300,9 @@ sub do_edit {
319
300
320
301
# Handle Uncouth Termination
321
302
sub signal_handler {
322
-
323
303
# Make text normal
324
- print color(" reset" ), " \n " ;
304
+ require Term::ANSIColor;
305
+ print Term::ANSIColor::color(" reset" ), " \n " ;
325
306
326
307
# SMTP password masked
327
308
system " stty echo" ;
@@ -602,11 +583,13 @@ sub config_regexp {
602
583
}
603
584
604
585
sub parse_address_line {
586
+ require Git::LoadCPAN::Mail::Address;
605
587
return map { $_ -> format } Mail::Address-> parse($_ [0]);
606
588
}
607
589
608
590
sub split_addrs {
609
- return quotewords(' \s*,\s*' , 1, @_ );
591
+ require Text::ParseWords;
592
+ return Text::ParseWords::quotewords(' \s*,\s*' , 1, @_ );
610
593
}
611
594
612
595
my %aliases ;
@@ -655,10 +638,11 @@ sub parse_sendmail_aliases {
655
638
s /\\ "/ "/ g foreach @addr ;
656
639
$aliases {$alias } = \@addr
657
640
}}},
658
- mailrc => sub { my $fh = shift ; while (<$fh >) {
641
+ mailrc => sub { my $fh = shift ; while (<$fh >) {
659
642
if (/ ^alias\s +(\S +)\s +(.*?)\s *$ / ) {
643
+ require Text::ParseWords;
660
644
# spaces delimit multiple addresses
661
- $aliases {$1 } = [ quotewords(' \s+' , 0, $2 ) ];
645
+ $aliases {$1 } = [ Text::ParseWords:: quotewords(' \s+' , 0, $2 ) ];
662
646
}}},
663
647
pine => sub { my $fh = shift ; my $f =' \t[^\t]*' ;
664
648
for (my $x = ' ' ; defined ($x ); $x = $_ ) {
@@ -730,7 +714,8 @@ sub is_format_patch_arg {
730
714
opendir my $dh , $f
731
715
or die sprintf (__(" Failed to opendir %s : %s " ), $f , $! );
732
716
733
- push @files , grep { -f $_ } map { catfile($f , $_ ) }
717
+ require File::Spec;
718
+ push @files , grep { -f $_ } map { File::Spec-> catfile($f , $_ ) }
734
719
sort readdir $dh ;
735
720
closedir $dh ;
736
721
} elsif ((-f $f or -p $f ) and !is_format_patch_arg($f )) {
@@ -743,7 +728,8 @@ sub is_format_patch_arg {
743
728
if (@rev_list_opts ) {
744
729
die __(" Cannot run git format-patch from outside a repository\n " )
745
730
unless $repo ;
746
- push @files , $repo -> command(' format-patch' , ' -o' , tempdir(CLEANUP => 1), @rev_list_opts );
731
+ require File::Temp;
732
+ push @files , $repo -> command(' format-patch' , ' -o' , File::Temp::tempdir(CLEANUP => 1), @rev_list_opts );
747
733
}
748
734
749
735
@files = handle_backup_files(@files );
@@ -780,9 +766,10 @@ sub get_patch_subject {
780
766
if ($compose ) {
781
767
# Note that this does not need to be secure, but we will make a small
782
768
# effort to have it be unique
769
+ require File::Temp;
783
770
$compose_filename = ($repo ?
784
- tempfile(" .gitsendemail.msg.XXXXXX" , DIR => $repo -> repo_path()) :
785
- tempfile(" .gitsendemail.msg.XXXXXX" , DIR => " ." ))[1];
771
+ File::Temp:: tempfile(" .gitsendemail.msg.XXXXXX" , DIR => $repo -> repo_path()) :
772
+ File::Temp:: tempfile(" .gitsendemail.msg.XXXXXX" , DIR => " ." ))[1];
786
773
open my $c , " >" , $compose_filename
787
774
or die sprintf (__(" Failed to open for writing %s : %s " ), $compose_filename , $! );
788
775
@@ -889,13 +876,27 @@ sub get_patch_subject {
889
876
do_edit(@files);
890
877
}
891
878
879
+ sub term {
880
+ my $term = eval {
881
+ require Term::ReadLine;
882
+ $ENV{"GIT_SEND_EMAIL_NOTTY"}
883
+ ? Term::ReadLine->new(' git-send -email' , \*STDIN, \*STDOUT)
884
+ : Term::ReadLine->new(' git-send -email' );
885
+ };
886
+ if ($@) {
887
+ $term = FakeTerm->new("$@: going non-interactive");
888
+ }
889
+ return $term;
890
+ }
891
+
892
892
sub ask {
893
893
my ($prompt, %arg) = @_;
894
894
my $valid_re = $arg{valid_re};
895
895
my $default = $arg{default};
896
896
my $confirm_only = $arg{confirm_only};
897
897
my $resp;
898
898
my $i = 0;
899
+ my $term = term();
899
900
return defined $default ? $default : undef
900
901
unless defined $term->IN and defined fileno($term->IN) and
901
902
defined $term->OUT and defined fileno($term->OUT);
@@ -1076,6 +1077,7 @@ sub extract_valid_address {
1076
1077
return $address if ($address =~ / ^($local_part_regexp )$ / );
1077
1078
1078
1079
$address =~ s / ^\s *<(.*)>\s *$/ $1 / ;
1080
+ my $have_email_valid = eval { require Email::Valid; 1 };
1079
1081
if ($have_email_valid ) {
1080
1082
return scalar Email::Valid-> address($address );
1081
1083
}
@@ -1135,7 +1137,8 @@ sub validate_address_list {
1135
1137
sub make_message_id {
1136
1138
my $uniq ;
1137
1139
if (!defined $message_id_stamp ) {
1138
- $message_id_stamp = strftime(" %Y%m%d%H%M%S .$$ " , gmtime (time ));
1140
+ require POSIX;
1141
+ $message_id_stamp = POSIX::strftime(" %Y%m%d%H%M%S .$$ " , gmtime (time ));
1139
1142
$message_id_serial = 0;
1140
1143
}
1141
1144
$message_id_serial ++;
@@ -1305,6 +1308,7 @@ sub valid_fqdn {
1305
1308
sub maildomain_net {
1306
1309
my $maildomain ;
1307
1310
1311
+ require Net::Domain;
1308
1312
my $domain = Net::Domain::domainname();
1309
1313
$maildomain = $domain if valid_fqdn($domain );
1310
1314
@@ -1315,6 +1319,7 @@ sub maildomain_mta {
1315
1319
my $maildomain ;
1316
1320
1317
1321
for my $host (qw( mailhost localhost) ) {
1322
+ require Net::SMTP;
1318
1323
my $smtp = Net::SMTP-> new($host );
1319
1324
if (defined $smtp ) {
1320
1325
my $domain = $smtp -> domain;
@@ -1994,13 +1999,15 @@ sub validate_patch {
1994
1999
1995
2000
if ($repo ) {
1996
2001
my $hooks_path = $repo -> command_oneline(' rev-parse' , ' --git-path' , ' hooks' );
1997
- my $validate_hook = catfile($hooks_path ,
2002
+ require File::Spec;
2003
+ my $validate_hook = File::Spec-> catfile($hooks_path ,
1998
2004
' sendemail-validate' );
1999
2005
my $hook_error ;
2000
2006
if (-x $validate_hook ) {
2001
- my $target = abs_path($fn );
2007
+ require Cwd;
2008
+ my $target = Cwd::abs_path($fn );
2002
2009
# The hook needs a correct cwd and GIT_DIR.
2003
- my $cwd_save = cwd();
2010
+ my $cwd_save = Cwd:: cwd();
2004
2011
chdir ($repo -> wc_path() or $repo -> repo_path())
2005
2012
or die (" chdir: $! " );
2006
2013
local $ENV {" GIT_DIR" } = $repo -> repo_path();
0 commit comments