Alien-Selenium
view release on metacpan or search on metacpan
inc/File/Fetch.pm view on Meta::CPAN
### write to the output file ourselves, since lynx ass_u_mes to much
my $local = FileHandle->new(">$to")
or (
warn ("Could not open '$to' for writing: $!\n"),
return
);
### dump to stdout ###
my $cmd = [
$lynx,
'-source',
"-auth=anonymous:$FROM_EMAIL",
$self->uri
];
### shell out ###
my $captured;
unless(run( command => $cmd,
buffer => \$captured,
verbose => $DEBUG )
) {
warn "Command failed: $captured";
return;
}
### print to local file ###
$local->print( $captured );
$local->close or return;
return $to;
} else {
$METHOD_FAIL->{'lynx'} = 1;
return;
}
}
### use /bin/ncftp to fetch files
sub _ncftp_fetch {
my $self = shift;
my %hash = @_;
my ($to);
my $tmpl = {
to => { required => 1, store => \$to }
};
check( $tmpl, \%hash ) or return;
### we can only set passive mode in interactive sesssions, so bail out
### if $FTP_PASSIVE is set
return if $FTP_PASSIVE;
### see if we have a wget binary ###
if( my $ncftp = can_run('ncftp') ) {
my $cmd = [
$ncftp,
'-V', # do not be verbose
'-p', $FROM_EMAIL, # email as password
$self->host, # hostname
dirname($to), # local dir for the file
# remote path to the file
File::Spec::Unix->catdir( $self->path, $self->file ),
];
### shell out ###
my $captured;
unless(run( command => $cmd,
buffer => \$captured,
verbose => $DEBUG )
) {
warn "Command failed: $captured";
return;
}
return $to;
} else {
$METHOD_FAIL->{'ncftp'} = 1;
return;
}
}
### use /bin/curl to fetch files
sub _curl_fetch {
my $self = shift;
my %hash = @_;
my ($to);
my $tmpl = {
to => { required => 1, store => \$to }
};
check( $tmpl, \%hash ) or return;
if (my $curl = can_run('curl')) {
### these long opts are self explanatory - I like that -jmb
my $cmd = [ $curl ];
push(@$cmd, '--silent') unless $DEBUG;
### curl does the right thing with passive, regardless ###
if ($self->scheme eq 'ftp') {
push(@$cmd, '--user', "anonymous:$FROM_EMAIL");
}
push @$cmd, '--fail', '--output', $to, $self->uri;
my $captured;
unless(run( command => $cmd,
buffer => \$captured,
verbose => $DEBUG )
) {
warn "command failed: $captured";
return;
}
return $to;
( run in 1.371 second using v1.01-cache-2.11-cpan-fa01517f264 )