AWS-S3
view release on metacpan or search on metacpan
lib/AWS/S3.pm view on Meta::CPAN
# Linode/Akamai E3 endpoints do not include the `xmlns` in
# ListAllMyBuckets, so use the localname to work with or
# without a declared XML namespace.
my $xml = $response->xml;
my @buckets = ();
foreach my $node ( $xml->getElementsByLocalName( 'Bucket' ) ) {
push @buckets,
AWS::S3::Bucket->new(
name => $node->getElementsByLocalName('Name')->string_value,
creation_date => $node->getElementsByLocalName('CreationDate')->string_value,
s3 => $s,
);
} # end foreach()
$LOG->debug('Listed AWS buckets', { buckets => [map $_->name, @buckets] });
return @buckets;
} # end buckets()
sub bucket {
my ( $s, $name ) = @_;
my ( $bucket ) = grep { $_->name eq $name } $s->buckets
or return;
$bucket;
} # end bucket()
sub add_bucket {
my ( $s, %args ) = @_;
my $type = 'CreateBucket';
my $request = $s->request(
$type,
bucket => $args{name},
(
$args{location} ? ( location => $args{location} )
: $s->region ? ( location => $s->region )
: ()
),
);
my $response = $request->request();
if ( my $msg = $response->friendly_error() ) {
die $msg;
} # end if()
return $s->bucket( $args{name} );
} # end add_bucket()
__PACKAGE__->meta->make_immutable;
__END__
=pod
=head1 NAME
AWS::S3 - Lightweight interface to Amazon S3 (Simple Storage Service)
=for html
<a href='https://travis-ci.org/leejo/AWS-S3?branch=master'><img src='https://travis-ci.org/leejo/AWS-S3.svg?branch=master' /></a>
<a href='https://coveralls.io/r/leejo/AWS-S3?branch=master'><img src='https://coveralls.io/repos/leejo/AWS-S3/badge.png?branch=master' alt='Coverage Status' /></a>
=head1 SYNOPSIS
use AWS::S3;
my $s3 = AWS::S3->new(
access_key_id => 'E654SAKIASDD64ERAF0O',
secret_access_key => 'LgTZ25nCD+9LiCV6ujofudY1D6e2vfK0R4GLsI4H',
session_token => 'IQob3JpJZ2luXJ2VjJEL7//////////wE...',
region => 'eu-west-1', # set to relevant AWS region
honor_leading_slashes => 0, # set to allow leading slashes in bucket names, defaults to 0
);
# Add a bucket:
my $bucket = $s3->add_bucket(
name => 'foo-bucket',
);
# Set the acl:
$bucket->acl( 'private' );
# Add a file:
my $new_file = $bucket->add_file(
key => 'foo/bar.txt',
contents => \'This is the contents of the file',
);
# You can also set the contents with a coderef:
# Coderef should eturn a reference, not the actual string of content:
$new_file = $bucket->add_file(
key => 'foo/bar.txt',
contents => sub { return \"This is the contents" }
);
# Get the file:
my $same_file = $bucket->file( 'foo/bar.txt' );
# Get the contents:
my $scalar_ref = $same_file->contents;
print $$scalar_ref;
# Update the contents with a scalar ref:
$same_file->contents( \"New file contents" );
# Update the contents with a code ref:
$same_file->contents( sub { return \"New file contents" } );
# Delete the file:
$same_file->delete();
# Iterate through lots of files:
my $iterator = $bucket->files(
page_size => 100,
page_number => 1,
);
while( my @files = $iterator->next_page )
{
warn "Page number: ", $iterator->page_number, "\n";
foreach my $file ( @files )
{
( run in 1.739 second using v1.01-cache-2.11-cpan-df04353d9ac )