Alien-wxWidgets
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
inc/inc_File-Fetch/File/Fetch.pm view on Meta::CPAN
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;
my @options = ($self->host);
push(@options, Timeout => $TIMEOUT) if $TIMEOUT;
unless( $ftp = Net::FTP->new( @options ) ) {
return $self->_error(loc("Ftp creation failed: %1",$@));
}
### login ###
unless( $ftp->login( anonymous => $FROM_EMAIL ) ) {
return $self->_error(loc("Could not login to '%1'",$self->host));
}
### set binary mode, just in case ###
$ftp->binary;
### create the remote path
### remember remote paths are unix paths! [#11483]
my $remote = File::Spec::Unix->catfile( $self->path, $self->file );
### fetch the file ###
my $target;
unless( $target = $ftp->get( $remote, $to ) ) {
return $self->_error(loc("Could not fetch '%1' from '%2'",
$remote, $self->host));
}
### log out ###
$ftp->quit;
return $target;
} else {
$METHOD_FAIL->{'netftp'} = 1;
return;
}
}
### /bin/wget fetch ###
sub _wget_fetch {
my $self = shift;
my %hash = @_;
my ($to);
my $tmpl = {
to => { required => 1, store => \$to }
};
check( $tmpl, \%hash ) or return;
### see if we have a wget binary ###
if( my $wget = can_run('wget') ) {
### no verboseness, thanks ###
my $cmd = [ $wget, '--quiet' ];
### if a timeout is set, add it ###
push(@$cmd, '--timeout=' . $TIMEOUT) if $TIMEOUT;
### run passive if specified ###
push @$cmd, '--passive-ftp' if $FTP_PASSIVE;
### set the output document, add the uri ###
push @$cmd, '--output-document',
### DO NOT quote things for IPC::Run, it breaks stuff.
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.682 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )