Alien-wxWidgets
view release on metacpan or search on metacpan
inc/inc_File-Fetch/File/Fetch.pm view on Meta::CPAN
### method is blacklisted ###
next if grep { lc $_ eq $method } @$BLACKLIST;
### method is known to fail ###
next if $METHOD_FAIL->{$method};
### there's serious issues with IPC::Run and quoting of command
### line arguments. using quotes in the wrong place breaks things,
### and in the case of say,
### C:\cygwin\bin\wget.EXE --quiet --passive-ftp --output-document
### "index.html" "http://www.cpan.org/index.html?q=1&y=2"
### it doesn't matter how you quote, it always fails.
local $IPC::Cmd::USE_IPC_RUN = 0;
if( my $file = $self->$sub(
to => File::Spec->catfile( $to, $self->output_file )
)){
unless( -e $file && -s _ ) {
$self->_error(loc("'%1' said it fetched '%2', ".
"but it was not created",$method,$file));
### mark the failure ###
$METHOD_FAIL->{$method} = 1;
next;
} else {
my $abs = File::Spec->rel2abs( $file );
return $abs;
}
}
}
### if we got here, we looped over all methods, but we weren't able
### to fetch it.
return;
}
########################
### _*_fetch methods ###
########################
### LWP fetching ###
sub _lwp_fetch {
my $self = shift;
my %hash = @_;
my ($to);
my $tmpl = {
to => { required => 1, store => \$to }
};
check( $tmpl, \%hash ) or return;
### modules required to download with lwp ###
my $use_list = {
LWP => '0.0',
'LWP::UserAgent' => '0.0',
'HTTP::Request' => '0.0',
'HTTP::Status' => '0.0',
URI => '0.0',
};
if( can_load(modules => $use_list) ) {
### setup the uri object
my $uri = URI->new( File::Spec::Unix->catfile(
$self->path, $self->file
) );
### special rules apply for file:// uris ###
$uri->scheme( $self->scheme );
$uri->host( $self->scheme eq 'file' ? '' : $self->host );
$uri->userinfo("anonymous:$FROM_EMAIL") if $self->scheme ne 'file';
### set up the useragent object
my $ua = LWP::UserAgent->new();
$ua->timeout( $TIMEOUT ) if $TIMEOUT;
$ua->agent( $USER_AGENT );
$ua->from( $FROM_EMAIL );
$ua->env_proxy;
my $res = $ua->mirror($uri, $to) or return;
### uptodate or fetched ok ###
if ( $res->code == 304 or $res->code == 200 ) {
return $to;
} else {
return $self->_error(loc("Fetch failed! HTTP response: %1 %2 [%3]",
$res->code, HTTP::Status::status_message($res->code),
$res->status_line));
}
} else {
$METHOD_FAIL->{'lwp'} = 1;
return;
}
}
### Net::FTP fetching
sub _netftp_fetch {
my $self = shift;
my %hash = @_;
my ($to);
my $tmpl = {
to => { required => 1, store => \$to }
};
check( $tmpl, \%hash ) or return;
### required modules ###
my $use_list = { 'Net::FTP' => 0 };
if( can_load( modules => $use_list ) ) {
### make connection ###
my $ftp;
( run in 1.560 second using v1.01-cache-2.11-cpan-e1769b4cff6 )