1 #line 1 "inc/Module/Install/Fetch.pm - /Library/Perl/5.8.6/Module/Install/Fetch.pm"
2 package Module::Install::Fetch;
4 use Module::Install::Base;
5 @ISA = qw(Module::Install::Base);
10 my ($self, %args) = @_;
11 my ($scheme, $host, $path, $file) =
12 $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
14 if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
15 $args{url} = $args{ftp_url}
16 or (warn("LWP support unavailable!\n"), return);
17 ($scheme, $host, $path, $file) =
18 $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
22 print "Fetching '$file' from $host... ";
24 unless (eval { require Socket; Socket::inet_aton($host) }) {
25 warn "'$host' resolve failed!\n";
29 return unless $scheme eq 'ftp' or $scheme eq 'http';
32 my $dir = Cwd::getcwd();
33 chdir $args{local_dir} or return if exists $args{local_dir};
35 if (eval { require LWP::Simple; 1 }) {
36 LWP::Simple::mirror($args{url}, $file);
38 elsif (eval { require Net::FTP; 1 }) { eval {
39 # use Net::FTP to get past firewall
40 my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600);
41 $ftp->login("anonymous", 'anonymous@example.com');
44 $ftp->get($file) or (warn("$!\n"), return);
47 elsif (my $ftp = $self->can_run('ftp')) { eval {
48 # no Net::FTP, fallback to ftp.exe
50 my $fh = FileHandle->new;
52 local $SIG{CHLD} = 'IGNORE';
53 unless ($fh->open("|$ftp -n")) {
54 warn "Couldn't open ftp: $!\n";
58 my @dialog = split(/\n/, << ".");
60 user anonymous anonymous\@example.com
66 foreach (@dialog) { $fh->print("$_\n") }
70 warn "No working 'ftp' program available!\n";
75 warn "Fetching failed: $@\n";
79 return if exists $args{size} and -s $file != $args{size};
80 system($args{run}) if exists $args{run};
81 unlink($file) if $args{remove};
83 print(((!exists $args{check_for} or -e $args{check_for})
84 ? "done!" : "failed! ($!)"), "\n");
85 chdir $dir; return !$?;