| 1 | package Net::Amazon::S3::Client; | ||||||||||
| 2 | # ABSTRACT: An easy-to-use Amazon S3 client | ||||||||||
| 3 | 99 | $Net::Amazon::S3::Client::VERSION = '0.992'; | |||||||||
| 4 | 99 | ▶ | use Moose 0.85; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 99 | ▶ | use HTTP::Status qw(status_message); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 99 | ▶ | use MooseX::StrictConstructor 0.16; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 99 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 99 | ▶ | use Net::Amazon::S3; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 99 | ▶ | use Net::Amazon::S3::Constraint::Etag; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 99 | ▶ | use Net::Amazon::S3::Error::Handler::Confess; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 99 | has 's3' => ( | |||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | isa => 'Net::Amazon::S3', | ||||||||||
| 16 | required => 1, | ||||||||||
| 17 | handles => [ | ||||||||||
| 18 | 'ua', | ||||||||||
| 19 | ], | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 99 | has error_handler_class => ( | |||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | lazy => 1, | ||||||||||
| 25 | default => 'Net::Amazon::S3::Error::Handler::Confess', | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | has error_handler => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | lazy => 1, | ||||||||||
| 31 | 144 | ▶ | default => sub { $_[0]->error_handler_class->new (s3 => $_[0]->s3) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 99 | ); | |||||||||
| 33 | |||||||||||
| 34 | 99 | has bucket_class => ( | |||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | init_arg => undef, | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | default => 'Net::Amazon::S3::Client::Bucket', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | 152 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 42 | 152 | my ($orig, $class) = (shift, shift); | |||||||||
| 43 | 152 | my $args = $class->$orig (@_); | |||||||||
| 44 | |||||||||||
| 45 | 152 | ▶ | unless (exists $args->{s3}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 2 | my $error_handler_class = delete $args->{error_handler_class}; | |||||||||
| 47 | 2 | my $error_handler = delete $args->{error_handler}; | |||||||||
| 48 | 2 | $args = { | |||||||||
| 49 | (error_handler_class => $error_handler_class) x!! defined $error_handler_class, | ||||||||||
| 50 | (error_handler => $error_handler ) x!! defined $error_handler, | ||||||||||
| 51 | s3 => Net::Amazon::S3->new ($args), | ||||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 152 | $args; | |||||||||
| 56 | 99 | }; | |||||||||
| 57 | |||||||||||
| 58 | 99 | __PACKAGE__->meta->make_immutable; | |||||||||
| 59 | |||||||||||
| 60 | 5 | ▶ | sub buckets { | ||||||||
|
Subroutine
buckets: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 61 | 5 | my $self = shift; | |||||||||
| 62 | 5 | my $s3 = $self->s3; | |||||||||
| 63 | |||||||||||
| 64 | 5 | my $response = $self->_perform_operation ( | |||||||||
| 65 | 'Net::Amazon::S3::Operation::Buckets::List', | ||||||||||
| 66 | ); | ||||||||||
| 67 | |||||||||||
| 68 | 2 | ▶ | return unless $response->is_success; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | 2 | my $owner_id = $response->owner_id; | |||||||||
| 71 | 2 | my $owner_display_name = $response->owner_displayname; | |||||||||
| 72 | |||||||||||
| 73 | 2 | my @buckets; | |||||||||
| 74 | 2 | foreach my $bucket ($response->buckets) { | |||||||||
| 75 | push @buckets, $self->bucket_class->new ( | ||||||||||
| 76 | client => $self, | ||||||||||
| 77 | name => $bucket->{name}, | ||||||||||
| 78 | creation_date => $bucket->{creation_date}, | ||||||||||
| 79 | 4 | owner_id => $owner_id, | |||||||||
| 80 | owner_display_name => $owner_display_name, | ||||||||||
| 81 | ); | ||||||||||
| 82 | |||||||||||
| 83 | } | ||||||||||
| 84 | 2 | return @buckets; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 17 | ▶ | sub create_bucket { | ||||||||
|
Subroutine
create_bucket: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 88 | 17 | my ( $self, %conf ) = @_; | |||||||||
| 89 | |||||||||||
| 90 | my $bucket = $self->bucket_class->new( | ||||||||||
| 91 | client => $self, | ||||||||||
| 92 | name => $conf{name}, | ||||||||||
| 93 | 17 | ); | |||||||||
| 94 | 17 | $bucket->_create(%conf); | |||||||||
| 95 | 6 | return $bucket; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 126 | ▶ | sub bucket { | ||||||||
|
Subroutine
bucket: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 99 | 126 | my ( $self, %conf ) = @_; | |||||||||
| 100 | 126 | return $self->bucket_class->new( | |||||||||
| 101 | client => $self, | ||||||||||
| 102 | %conf, | ||||||||||
| 103 | ); | ||||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 144 | ▶ | sub _perform_operation { | ||||||||
|
Subroutine
_perform_operation: called CC=1 SCAR=0.0
| |||||||||||
| 107 | 144 | my ($self, $operation, %params) = @_; | |||||||||
| 108 | |||||||||||
| 109 | 144 | return $self->s3->_perform_operation ( | |||||||||
| 110 | $operation, | ||||||||||
| 111 | error_handler => $self->error_handler, | ||||||||||
| 112 | %params | ||||||||||
| 113 | ); | ||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 99 | 1; | |||||||||
| 117 | |||||||||||
| 118 | __END__ | ||||||||||