2 package Module
::Install
::Fetch
;
5 use Module
::Install
::Base
();
7 use vars
qw{$VERSION @ISA $ISCORE};
10 @ISA = 'Module::Install::Base';
15 my ($self, %args) = @_;
16 my ($scheme, $host, $path, $file) =
17 $args{url
} =~ m
|^(\w
+)://([^/]+)(.+)/(.+)| or return;
19 if ( $scheme eq 'http' and ! eval { require LWP
::Simple
; 1 } ) {
20 $args{url
} = $args{ftp_url
}
21 or (warn("LWP support unavailable!\n"), return);
22 ($scheme, $host, $path, $file) =
23 $args{url
} =~ m
|^(\w
+)://([^/]+)(.+)/(.+)| or return;
27 print "Fetching '$file' from $host... ";
29 unless (eval { require Socket
; Socket
::inet_aton
($host) }) {
30 warn "'$host' resolve failed!\n";
34 return unless $scheme eq 'ftp' or $scheme eq 'http';
37 my $dir = Cwd
::getcwd
();
38 chdir $args{local_dir
} or return if exists $args{local_dir
};
40 if (eval { require LWP
::Simple
; 1 }) {
41 LWP
::Simple
::mirror
($args{url
}, $file);
43 elsif (eval { require Net
::FTP
; 1 }) { eval {
44 # use Net::FTP to get past firewall
45 my $ftp = Net
::FTP
->new($host, Passive
=> 1, Timeout
=> 600);
46 $ftp->login("anonymous", 'anonymous@example.com');
49 $ftp->get($file) or (warn("$!\n"), return);
52 elsif (my $ftp = $self->can_run('ftp')) { eval {
53 # no Net::FTP, fallback to ftp.exe
55 my $fh = FileHandle
->new;
57 local $SIG{CHLD
} = 'IGNORE';
58 unless ($fh->open("|$ftp -n")) {
59 warn "Couldn't open ftp: $!\n";
63 my @dialog = split(/\n/, <<"END_FTP");
65 user anonymous anonymous\@example.com
71 foreach (@dialog) { $fh->print("$_\n") }
75 warn "No working 'ftp' program available!\n";
80 warn "Fetching failed: $@\n";
84 return if exists $args{size} and -s $file != $args{size};
85 system($args{run}) if exists $args{run};
86 unlink($file) if $args{remove};
88 print(((!exists $args{check_for} or -e $args{check_for})
89 ? "done!" : "failed! ($!)"), "\n");
90 chdir $dir; return !$?;