Amazon-S3Curl-PurePerl

 view release on metacpan or  search on metacpan

lib/Amazon/S3Curl/PurePerl.pm  view on Meta::CPAN

}

sub head_cmd {
    my $args = shift->_req('HEAD');
    splice( @$args, $#$args, 0, qw[ -I -X HEAD ] );
    return $args;
}

sub url_exists {
    my $self = shift;
    my @args = grep { !/-f/ } @{ $self->head_cmd }; #take out fail mode, want to parse and look for the 404.
    log_info { "running " . join( " ", @_ ) } @args;
    my @output = capture( @args );
    die "no output received!" unless @output;
    return 1 if $output[0] =~ /200 OK/;
    return 0 if $output[0] =~ /404 Not Found/;
    die "url_exists did not find a 200 or 404: $output[0]";
}

sub _exec {
    my($self,$method) = @_;
    my $meth = $method."_cmd";
    die "cannot $meth" unless $self->can($meth);
    my $args = $self->$meth;
    log_info { "running " . join( " ", @_ ) } @$args;
    capture(@$args);
    return 1;

lib/Amazon/S3Curl/PurePerl.pm  view on Meta::CPAN


=head2 upload_cmd

Just get the command to execute in the form of an arrayref, don't actually execute it:

    my $cmd = $s3curl->download_cmd;
    system(@$cmd);

=head2 url_exists

Check to see if a given url returns a 404 or 200. return 1 if 200, return 0 if 404, die otherwise.

=head1 LICENSE

This library is free software and may be distributed under the same terms as perl itself.

=head1 AUTHOR AND CONTRIBUTORS

This distribution was
adapted by Samuel Kaufman L<skaufman@cpan.org> from the L<Amazon S3 Authentication Tool for Curl|http://aws.amazon.com/code/128>

xt/s3curl.t  view on Meta::CPAN


ok my $should_die = Amazon::S3Curl::PurePerl->new(%pp_args, local_file => undef );
eval {
    $should_die->download;
    fail "should've died";
};
ok $@, "died without local_file param.";
my $ret1 = system(@{ $uploader->upload_cmd });
my $ret2 = system(@{ $downloader->download_cmd });
ok $downloader->delete, "delete remote file";
ok !$downloader->url_exists, "file is gone (404)";
diag $ret1;
ok !$ret1,"uploaded using upload_cmd => system";
ok !$ret2,"downloaded using download_cmd => system";



( run in 2.040 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )