File Coverage

blib/lib/Net/Amazon/S3.pm
Criterion Covered Total %
statement 221 243 90.9
branch 27 36 75.0
condition 2 6 33.3
subroutine 58 59 98.3
pod 6 10 60.0
total 314 354 88.7


line stmt bran cond sub pod time code
1             # ABSTRACT: Use the Amazon S3 - Simple Storage Service
2             $Net::Amazon::S3::VERSION = '0.991';
3             use Moose 0.85;
4 99     99   843632 use MooseX::StrictConstructor 0.16;
  99         22881044  
  99         698  
5 99     99   606176  
  99         1265885  
  99         490  
6             use Carp;
7 99     99   603391 use Digest::HMAC_SHA1;
  99         229  
  99         5723  
8 99     99   42344 use Safe::Isa ();
  99         420023  
  99         3512  
9 99     99   1310  
  99         971  
  99         1485  
10             use Net::Amazon::S3::Bucket;
11 99     99   43774 use Net::Amazon::S3::Client;
  99         386  
  99         4977  
12 99     99   33299 use Net::Amazon::S3::Client::Bucket;
  99         261  
  99         3087  
13 99     99   46891 use Net::Amazon::S3::Client::Object;
  99         382  
  99         3730  
14 99     99   62456 use Net::Amazon::S3::Error::Handler::Legacy;
  99         395  
  99         4230  
15 99     99   52852 use Net::Amazon::S3::HTTPRequest;
  99         314  
  99         3067  
16 99     99   38960 use Net::Amazon::S3::Request;
  99         376  
  99         4037  
17 99     99   48876 use Net::Amazon::S3::Response;
  99         367  
  99         3882  
18 99     99   46228 use Net::Amazon::S3::Operation::Bucket::Acl::Fetch;
  99         373  
  99         4151  
19 99     99   45080 use Net::Amazon::S3::Operation::Bucket::Acl::Set;
  99         389  
  99         3711  
20 99     99   37231 use Net::Amazon::S3::Operation::Bucket::Create;
  99         358  
  99         3562  
21 99     99   36376 use Net::Amazon::S3::Operation::Bucket::Delete;
  99         357  
  99         3721  
22 99     99   35852 use Net::Amazon::S3::Operation::Bucket::Location;
  99         490  
  99         3605  
23 99     99   35478 use Net::Amazon::S3::Operation::Bucket::Tags::Add;
  99         307  
  99         3342  
24 99     99   37758 use Net::Amazon::S3::Operation::Bucket::Tags::Delete;
  99         338  
  99         3492  
25 99     99   36823 use Net::Amazon::S3::Operation::Buckets::List;
  99         304  
  99         3383  
26 99     99   38829 use Net::Amazon::S3::Operation::Object::Acl::Fetch;
  99         309  
  99         3241  
27 99     99   38182 use Net::Amazon::S3::Operation::Object::Acl::Set;
  99         356  
  99         3640  
28 99     99   38487 use Net::Amazon::S3::Operation::Object::Add;
  99         362  
  99         3531  
29 99     99   36020 use Net::Amazon::S3::Operation::Object::Delete;
  99         376  
  99         3873  
30 99     99   36948 use Net::Amazon::S3::Operation::Object::Fetch;
  99         336  
  99         3542  
31 99     99   36624 use Net::Amazon::S3::Operation::Object::Head;
  99         345  
  99         3509  
32 99     99   36547 use Net::Amazon::S3::Operation::Object::Restore;
  99         356  
  99         3454  
33 99     99   36272 use Net::Amazon::S3::Operation::Object::Tags::Add;
  99         374  
  99         3692  
34 99     99   37696 use Net::Amazon::S3::Operation::Object::Tags::Delete;
  99         367  
  99         3737  
35 99     99   37011 use Net::Amazon::S3::Operation::Object::Upload::Abort;
  99         356  
  99         3454  
36 99     99   38258 use Net::Amazon::S3::Operation::Object::Upload::Complete;
  99         364  
  99         3623  
37 99     99   37454 use Net::Amazon::S3::Operation::Object::Upload::Create;
  99         361  
  99         3647  
38 99     99   39669 use Net::Amazon::S3::Operation::Object::Upload::Part;
  99         369  
  99         3683  
39 99     99   38471 use Net::Amazon::S3::Operation::Object::Upload::Parts;
  99         376  
  99         3803  
40 99     99   38336 use Net::Amazon::S3::Operation::Objects::Delete;
  99         344  
  99         3589  
41 99     99   37139 use Net::Amazon::S3::Operation::Objects::List;
  99         658  
  99         3661  
42 99     99   36833 use Net::Amazon::S3::Signature::V2;
  99         385  
  99         3646  
43 99     99   676 use Net::Amazon::S3::Signature::V4;
  99         235  
  99         2201  
44 99     99   37583 use Net::Amazon::S3::Utils;
  99         390  
  99         3260  
45 99     99   73237 use Net::Amazon::S3::Vendor;
  99         271  
  99         3212  
46 99     99   36430 use Net::Amazon::S3::Vendor::Amazon;
  99         318  
  99         3395  
47 99     99   43481 use LWP::UserAgent::Determined;
  99         326  
  99         3140  
48 99     99   43487 use URI::Escape qw(uri_escape_utf8);
  99         44629  
  99         2945  
49 99     99   678  
  99         225  
  99         162210  
50             my $AMAZON_S3_HOST = 's3.amazonaws.com';
51              
52             has authorization_context => (
53             is => 'ro',
54             isa => 'Net::Amazon::S3::Authorization',
55             required => 0,
56              
57             handles => {
58             aws_access_key_id => 'aws_access_key_id',
59             aws_secret_access_key => 'aws_secret_access_key',
60             aws_session_token => 'aws_session_token',
61             },
62             );
63              
64             has vendor => (
65             is => 'ro',
66             isa => 'Net::Amazon::S3::Vendor',
67             required => 1,
68              
69             handles => {
70             authorization_method => 'authorization_method',
71             host => 'host',
72             secure => 'use_https',
73             use_virtual_host => 'use_virtual_host',
74             },
75             );
76              
77             has 'timeout' => ( is => 'ro', isa => 'Num', required => 0, default => 30 );
78             has 'retry' => ( is => 'ro', isa => 'Bool', required => 0, default => 0 );
79             has 'ua'
80             => is => 'rw'
81             => isa => 'LWP::UserAgent'
82             => required => 0
83             => lazy => 1
84             => builder => '_build_ua'
85             ;
86             has 'err' => ( is => 'rw', isa => 'Maybe[Str]', required => 0 );
87             has 'errstr' => ( is => 'rw', isa => 'Maybe[Str]', required => 0 );
88             has keep_alive_cache_size => ( is => 'ro', isa => 'Int', required => 0, default => 10 );
89              
90             has error_handler_class => (
91             is => 'ro',
92             lazy => 1,
93             default => 'Net::Amazon::S3::Error::Handler::Legacy',
94             );
95              
96             has error_handler => (
97             is => 'ro',
98             lazy => 1,
99             default => sub { $_[0]->error_handler_class->new (s3 => $_[0]) },
100             );
101              
102             has bucket_class => (
103             is => 'ro',
104             init_arg => undef,
105             lazy => 1,
106             default => 'Net::Amazon::S3::Bucket',
107             );
108              
109             my ($args) = @_;
110              
111 415     415   862 my $aws_access_key_id = delete $args->{aws_access_key_id};
112             my $aws_secret_access_key = delete $args->{aws_secret_access_key};
113 415         939 my $use_iam_role = delete $args->{use_iam_role};
114 415         851 my $aws_session_token = delete $args->{aws_session_token};
115 415         811  
116 415         1229 if ($args->{authorization_context}) {
117             return $args->{authorization_context};
118 415 50       1144 }
119 0         0  
120             if ($use_iam_role || $aws_session_token) {
121             require Net::Amazon::S3::Authorization::IAM;
122 415 100 66     1772  
123 1         376 return Net::Amazon::S3::Authorization::IAM->new (
124             aws_access_key_id => $aws_access_key_id,
125 1         9 aws_secret_access_key => $aws_secret_access_key,
126             aws_session_token => $aws_session_token,
127             )
128             }
129              
130             require Net::Amazon::S3::Authorization::Basic;
131              
132 414         37598 return Net::Amazon::S3::Authorization::Basic->new (
133             aws_access_key_id => $aws_access_key_id,
134 414         2493 aws_secret_access_key => $aws_secret_access_key,
135             );
136             }
137              
138             my ($args) = @_;
139              
140             my %backward =
141 415     415   931 map { $_ => delete $args->{$_} }
142             grep { exists $args->{$_} }
143             qw[ host secure use_virtual_host authorization_method ]
144 1288         2809 ;
145 415         941  
  1660         3001  
146             return $args->{vendor}
147             if $args->{vendor};
148              
149             $backward{host} = $AMAZON_S3_HOST
150 415 100       1556 unless exists $backward{host};
151              
152             $backward{use_https} = delete $backward{secure}
153 413 100       1398 if exists $backward{secure};
154              
155             my $vendor_class = $backward{host} eq $AMAZON_S3_HOST
156 413 100       1310 ? 'Net::Amazon::S3::Vendor::Amazon'
157             : 'Net::Amazon::S3::Vendor'
158 413 100       1328 ;
159              
160             return $vendor_class->new (%backward);
161             }
162              
163 413         3193 around BUILDARGS => sub {
164             my ($orig, $class) = (shift, shift);
165             my $args = $class->$orig (@_);
166              
167             # support compat authorization arguments
168             $args->{authorization_context} = _build_arg_authorization_context $args;
169             $args->{vendor} = _build_arg_vendor $args;
170              
171             $args;
172             };
173              
174              
175             my $self = shift;
176              
177             my $ua;
178             if ( $self->retry ) {
179 0     0   0 $ua = LWP::UserAgent::Determined->new(
180             keep_alive => $self->keep_alive_cache_size,
181 0         0 requests_redirectable => [qw(GET HEAD DELETE PUT POST)],
182 0 0       0 );
183 0         0 $ua->timing('1,2,4,8,16,32');
184             } else {
185             $ua = LWP::UserAgent->new(
186             keep_alive => $self->keep_alive_cache_size,
187 0         0 requests_redirectable => [qw(GET HEAD DELETE PUT POST)],
188             );
189 0         0 }
190              
191             $ua->timeout( $self->timeout );
192             $ua->env_proxy;
193              
194             return $ua;
195 0         0 }
196 0         0  
197             my ($self, %args) = @_;
198 0         0  
199             my $response = $self->_perform_operation (
200             'Net::Amazon::S3::Operation::Buckets::List',
201             %args,
202 5     5 1 15 );
203              
204 5         25 return unless $response->is_success;
205              
206             my $owner_id = $response->owner_id;;
207             my $owner_displayname = $response->owner_displayname;
208              
209 4 100       27 my @buckets;
210             foreach my $bucket ($response->buckets) {
211 2         52 push @buckets, $self->bucket_class->new (
212 2         9 account => $self,
213             bucket => $bucket->{name},
214 2         7 creation_date => $bucket->{creation_date},
215 2         7 );
216              
217             }
218              
219             return +{
220 4         106 owner_id => $owner_id,
221             owner_displayname => $owner_displayname,
222             buckets => \@buckets,
223             };
224             }
225 2         15  
226             my $self = shift;
227             my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_);
228              
229             my $response = $self->_perform_operation (
230             'Net::Amazon::S3::Operation::Bucket::Create',
231              
232 27     27 1 49 %args,
233 27         142 );
234              
235 27         118 return unless $response->is_success;
236              
237             return $self->bucket ($args{bucket});
238             }
239              
240             my $self = shift;
241 11 100       51 my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_);
242              
243 7         132 return $args{bucket}
244             if $args{bucket}->$Safe::Isa::_isa ($self->bucket_class);
245              
246             return $self->bucket_class->new ({
247 149     149 1 2081 account => $self,
248 149         1037 bucket => $args{bucket},
249             (region => $args{region}) x defined $args{region},
250             });
251 149 100       4356 }
252              
253             my $self = shift;
254             my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_);
255              
256             croak 'must specify bucket'
257 148         4277 unless defined $args{bucket};
258              
259             my $response = $self->_perform_operation (
260             'Net::Amazon::S3::Operation::Bucket::Delete',
261 9     9 1 17 %args,
262 9         53 );
263              
264             return unless $response->is_success;
265 9 50       29  
266             return 1;
267 9         32 }
268              
269             my $self = shift;
270             my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_);
271              
272 5 100       26 my $response = $self->_perform_operation (
273             'Net::Amazon::S3::Operation::Objects::List',
274 1         24 %args,
275             );
276              
277             return unless $response->is_success;
278 16     16 1 30  
279 16         88 my $return = {
280             bucket => $response->bucket,
281 16         75 prefix => $response->prefix,
282             marker => $response->marker,
283             next_marker => $response->next_marker,
284             max_keys => $response->max_keys,
285             is_truncated => $response->is_truncated,
286 8 100       82 };
287              
288 5         110 my @keys;
289             foreach my $node ($response->contents) {
290             push @keys, {
291             key => $node->{key},
292             last_modified => $node->{last_modified},
293             etag => $node->{etag},
294             size => $node->{size},
295             storage_class => $node->{storage_class},
296             owner_id => $node->{owner}{id},
297 5         10 owner_displayname => $node->{owner}{displayname},
298 5         20 };
299             }
300             $return->{keys} = \@keys;
301              
302             if ( $args{delimiter} ) {
303             $return->{common_prefixes} = [ $response->common_prefixes ];
304             }
305              
306             return $return;
307 7         40 }
308              
309 5         12 my $self = shift;
310             my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_);
311 5 100       13  
312 2         8 my $bucket = $args{bucket};
313             croak 'must specify bucket' unless $bucket;
314              
315 5         25 my $response = $self->list_bucket (%args);
316             return $response unless $response->{is_truncated};
317             my $all = $response;
318              
319 4     4 1 5 while (1) {
320 4         12 my $next_marker = $response->{next_marker}
321             || $response->{keys}->[-1]->{key};
322 4         11 $response = $self->list_bucket (
323 4 50       7 %args,
324             marker => $next_marker,
325 4         10 );
326 0 0       0 push @{ $all->{keys} }, @{ $response->{keys} };
327 0         0 last unless $response->{is_truncated};
328             }
329 0         0  
330             delete $all->{is_truncated};
331 0   0     0 delete $all->{next_marker};
332 0         0 return $all;
333             }
334              
335             # compat wrapper; deprecated as of 2005-03-23
336 0         0 my $self = shift;
  0         0  
  0         0  
337 0 0       0 my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (\@_);
338              
339             my $bucket = $self->bucket (delete $args{bucket});
340 0         0 return $bucket->add_key (%args);
341 0         0 }
342 0         0  
343             # compat wrapper; deprecated as of 2005-03-23
344             my $self = shift;
345             my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (\@_);
346              
347 2     2 0 4 my $bucket = $self->bucket (delete $args{bucket});
348 2         9 return $bucket->get_key (%args);
349             }
350 2         10  
351 2         12 # compat wrapper; deprecated as of 2005-03-23
352             my ( $self, $conf ) = @_;
353             my $bucket = $self->bucket (delete $conf->{bucket});
354             return $bucket->head_key( $conf->{key} );
355             }
356 2     2 0 5  
357 2         16 # compat wrapper; deprecated as of 2005-03-23
358             my $self = shift;
359 2         12 my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (\@_);
360 2         14  
361             my $bucket = $self->bucket (delete $args{bucket});
362             return $bucket->delete_key (%args);
363             }
364              
365 1     1 0 5 my ($self, $operation, %params) = @_;
366 1         5  
367 1         6 my $error_handler = delete $params{error_handler};
368             $error_handler = $self->error_handler unless defined $error_handler;
369              
370             my $request_class = $operation . '::Request';
371             my $response_class = $operation . '::Response';
372 2     2 0 5 my $filename = delete $params{filename};
373 2         9  
374             my $request = $request_class->new (s3 => $self, %params);
375 2         10 my $http_response = $self->ua->request ($request->http_request, $filename);
376 2         9 my $response = $response_class->new (http_response => $http_response);
377              
378             $error_handler->handle_error ($response);
379              
380 210     210   745 return $response;
381             }
382 210         475  
383 210 100       3122 my ( $self, $unencoded ) = @_;
384             return uri_escape_utf8( $unencoded, '^A-Za-z0-9_~\-\.' );
385 210         547 }
386 210         423  
387 210         416 __PACKAGE__->meta->make_immutable;
388              
389 210         8131 1;
390 210         4976  
391 210         139200  
392             =pod
393 210         173703  
394             =encoding UTF-8
395 138         4628  
396             =head1 NAME
397              
398             Net::Amazon::S3 - Use the Amazon S3 - Simple Storage Service
399 394     394   784  
400 394         1184 =head1 VERSION
401              
402             version 0.991
403              
404             =head1 SYNOPSIS
405              
406             use Net::Amazon::S3;
407             use Net::Amazon::S3::Authorization::Basic;
408             use Net::Amazon::S3::Authorization::IAM;
409             my $aws_access_key_id = 'fill me in';
410             my $aws_secret_access_key = 'fill me in too';
411              
412             my $s3 = Net::Amazon::S3->new (
413             authorization_context => Net::Amazon::S3::Authorization::Basic->new (
414             aws_access_key_id => $aws_access_key_id,
415             aws_secret_access_key => $aws_secret_access_key,
416             ),
417             retry => 1,
418             );
419              
420             # or use an IAM role.
421             my $s3 = Net::Amazon::S3->new (
422             authorization_context => Net::Amazon::S3::Authorization::IAM->new (
423             aws_access_key_id => $aws_access_key_id,
424             aws_secret_access_key => $aws_secret_access_key,
425             ),
426             retry => 1,
427             );
428              
429             # a bucket is a globally-unique directory
430             # list all buckets that i own
431             my $response = $s3->buckets;
432             foreach my $bucket ( @{ $response->{buckets} } ) {
433             print "You have a bucket: " . $bucket->bucket . "\n";
434             }
435              
436             # create a new bucket
437             my $bucketname = 'acmes_photo_backups';
438             my $bucket = $s3->add_bucket( { bucket => $bucketname } )
439             or die $s3->err . ": " . $s3->errstr;
440              
441             # or use an existing bucket
442             $bucket = $s3->bucket($bucketname);
443              
444             # store a file in the bucket
445             $bucket->add_key_filename( '1.JPG', 'DSC06256.JPG',
446             { content_type => 'image/jpeg', },
447             ) or die $s3->err . ": " . $s3->errstr;
448              
449             # store a value in the bucket
450             $bucket->add_key( 'reminder.txt', 'this is where my photos are backed up' )
451             or die $s3->err . ": " . $s3->errstr;
452              
453             # list files in the bucket
454             $response = $bucket->list_all
455             or die $s3->err . ": " . $s3->errstr;
456             foreach my $key ( @{ $response->{keys} } ) {
457             my $key_name = $key->{key};
458             my $key_size = $key->{size};
459             print "Bucket contains key '$key_name' of size $key_size\n";
460             }
461              
462             # fetch file from the bucket
463             $response = $bucket->get_key_filename( '1.JPG', 'GET', 'backup.jpg' )
464             or die $s3->err . ": " . $s3->errstr;
465              
466             # fetch value from the bucket
467             $response = $bucket->get_key('reminder.txt')
468             or die $s3->err . ": " . $s3->errstr;
469             print "reminder.txt:\n";
470             print " content length: " . $response->{content_length} . "\n";
471             print " content type: " . $response->{content_type} . "\n";
472             print " etag: " . $response->{content_type} . "\n";
473             print " content: " . $response->{value} . "\n";
474              
475             # delete keys
476             $bucket->delete_key('reminder.txt') or die $s3->err . ": " . $s3->errstr;
477             $bucket->delete_key('1.JPG') or die $s3->err . ": " . $s3->errstr;
478              
479             # and finally delete the bucket
480             $bucket->delete_bucket or die $s3->err . ": " . $s3->errstr;
481              
482             =head1 DESCRIPTION
483              
484             This module provides a Perlish interface to Amazon S3. From the
485             developer blurb: "Amazon S3 is storage for the Internet. It is
486             designed to make web-scale computing easier for developers. Amazon S3
487             provides a simple web services interface that can be used to store and
488             retrieve any amount of data, at any time, from anywhere on the web. It
489             gives any developer access to the same highly scalable, reliable,
490             fast, inexpensive data storage infrastructure that Amazon uses to run
491             its own global network of web sites. The service aims to maximize
492             benefits of scale and to pass those benefits on to developers".
493              
494             To find out more about S3, please visit: http://s3.amazonaws.com/
495              
496             To use this module you will need to sign up to Amazon Web Services and
497             provide an "Access Key ID" and " Secret Access Key". If you use this
498             module, you will incurr costs as specified by Amazon. Please check the
499             costs. If you use this module with your Access Key ID and Secret
500             Access Key you must be responsible for these costs.
501              
502             I highly recommend reading all about S3, but in a nutshell data is
503             stored in values. Values are referenced by keys, and keys are stored
504             in buckets. Bucket names are global.
505              
506             Note: This is the legacy interface, please check out
507             L<Net::Amazon::S3::Client> instead.
508              
509             Development of this code happens here: https://github.com/rustyconover/net-amazon-s3
510              
511             =head2 Bucket names with dots, HTTPS, and Signature V4
512              
513             At the moment Amazon S3 doesn't play well with HTTPS and virtual bucket hosts
514             if bucket name contains dots.
515              
516             Due the current implementation of Signature V4 handling you should use workaround
517             consisting of usage of region hostnames
518              
519             my $bucket_region = $global_s3->bucket ($bucket)->_head_region;
520              
521             my $region_s3 = Net::Amazon:S3->new (
522             ...,
523             vendor => Net::Amazon::S3::Vendor::Amazon->new (
524             host => "s3-$bucket_region.amazonaws.com",
525             use_virtual_host => 0,
526             ),
527             );
528              
529             my $bucket = $region_s3->bucket ($bucket);
530              
531             And use bucket instance / region s3 connection.
532              
533             =head1 METHODS
534              
535             =head2 new
536              
537             Create a new S3 client object. Takes some arguments:
538              
539             =over
540              
541             =item authorization_context
542              
543             Class that provides authorization information.
544              
545             See one of available implementations for more
546              
547             =over
548              
549             =item L<Net::Amazon::S3::Authorization::Basic>
550              
551             =item L<Net::Amazon::S3::Authorization::IAM>
552              
553             =back
554              
555             =item vendor
556              
557             Instance of L<Net::Amazon::S3::Vendor> holding vendor specific deviations.
558              
559             S3 became widely used object storage protocol with many vendors providing
560             different feature sets and different compatibility level.
561              
562             One common difference is bucket's HEAD request to determine its region.
563              
564             To maintain currently known differences along with any differencies that
565             may rise in feature it's better to hold vendor specification in dedicated
566             classes. This also allows users to build their own fine-tuned vendor classes.
567              
568             =over
569              
570             =item L<Net::Amazon::S3::Vendor::Amazon>
571              
572             =item L<Net::Amazon::S3::Vendor::Generic>
573              
574             =back
575              
576             =item aws_access_key_id
577              
578             Deprecated.
579              
580             When used it's used to create authorization context.
581              
582             Use your Access Key ID as the value of the AWSAccessKeyId parameter
583             in requests you send to Amazon Web Services (when required). Your
584             Access Key ID identifies you as the party responsible for the
585             request.
586              
587             =item aws_secret_access_key
588              
589             Deprecated.
590              
591             When used it's used to create authorization context.
592              
593             Since your Access Key ID is not encrypted in requests to AWS, it
594             could be discovered and used by anyone. Services that are not free
595             require you to provide additional information, a request signature,
596             to verify that a request containing your unique Access Key ID could
597             only have come from you.
598              
599             DO NOT INCLUDE THIS IN SCRIPTS OR APPLICATIONS YOU DISTRIBUTE. YOU'LL BE SORRY
600              
601             =item aws_session_token
602              
603             Deprecated.
604              
605             When used it's used to create authorization context.
606              
607             If you are using temporary credentials provided by the AWS Security Token
608             Service, set the token here, and it will be added to the request in order to
609             authenticate it.
610              
611             =item use_iam_role
612              
613             Deprecated.
614              
615             When used it's used to create authorization context.
616              
617             If you'd like to use IAM provided temporary credentials, pass this option
618             with a true value.
619              
620             =item secure
621              
622             Deprecated.
623              
624             Set this to C<0> if you don't want to use SSL-encrypted connections when talking
625             to S3. Defaults to C<1>.
626              
627             To use SSL-encrypted connections, LWP::Protocol::https is required.
628              
629             See L<#vendor> and L<Net::Amazon::S3::Vendor>.
630              
631             =item keep_alive_cache_size
632              
633             Set this to C<0> to disable Keep-Alives. Default is C<10>.
634              
635             =item timeout
636              
637             How many seconds should your script wait before bailing on a request to S3? Defaults
638             to 30.
639              
640             =item retry
641              
642             If this library should retry upon errors. This option is recommended.
643             This uses exponential backoff with retries after 1, 2, 4, 8, 16, 32 seconds,
644             as recommended by Amazon. Defaults to off.
645              
646             When retry is on, request will be automatically retried when one of following
647             HTTP statuses happens
648              
649             =over
650              
651             =item 408 - Request Timeout
652              
653             =item 500 - Internal Server Error
654              
655             =item 502 - Bad Gateway
656              
657             =item 503 - Service Unavailable
658              
659             =item 504 - Gateway Timeout
660              
661             =back
662              
663             For more details see L<LWP::UserAgent::Determined>.
664              
665             =item host
666              
667             Deprecated.
668              
669             The S3 host endpoint to use. Defaults to 's3.amazonaws.com'. This allows
670             you to connect to any S3-compatible host.
671              
672             See L<#vendor> and L<Net::Amazon::S3::Vendor>.
673              
674             =item use_virtual_host
675              
676             Deprecated.
677              
678             Use the virtual host method ('bucketname.s3.amazonaws.com') instead of specifying the
679             bucket at the first part of the path. This is particularly useful if you want to access
680             buckets not located in the US-Standard region (such as EU, Asia Pacific or South America).
681             See L<http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html> for the pros and cons.
682              
683             See L<#vendor> and L<Net::Amazon::S3::Vendor>.
684              
685             =item authorization_method
686              
687             Deprecated.
688              
689             Authorization implementation package name.
690              
691             This library provides L<< Net::Amazon::S3::Signature::V2 >> and L<< Net::Amazon::S3::Signature::V4 >>
692              
693             Default is Signature 4 if host is C<< s3.amazonaws.com >>, Signature 2 otherwise
694              
695             See L<#vendor> and L<Net::Amazon::S3::Vendor>.
696              
697             =item error_handler_class
698              
699             Error handler class name (package name), see L<< Net::Amazon::S3::Error::Handler >>
700             for more.
701              
702             Default: L<< Net::Amazon::S3::Error::Handler::Legacy >>
703              
704             =item error_handler
705              
706             Instance of error handler class.
707              
708             =back
709              
710             =head3 Notes
711              
712             When using L<Net::Amazon::S3> in child processes using fork (such as in
713             combination with the excellent L<Parallel::ForkManager>) you should create the
714             S3 object in each child, use a fresh LWP::UserAgent in each child, or disable
715             the L<LWP::ConnCache> in the parent:
716              
717             $s3->ua( LWP::UserAgent->new(
718             keep_alive => 0, requests_redirectable => [qw'GET HEAD DELETE PUT POST'] );
719              
720             =head2 buckets
721              
722             Returns undef on error, else hashref of results
723              
724             =head2 add_bucket
725              
726             # Create new bucket with default location
727             my $bucket = $s3->add_bucket ('new-bucket');
728              
729             # Create new bucket in another location
730             my $bucket = $s3->add_bucket ('new-bucket', location_constraint => 'eu-west-1');
731             my $bucket = $s3->add_bucket ('new-bucket', { location_constraint => 'eu-west-1' });
732             my $bucket = $s3->add_bucket (bucket => 'new-bucket', location_constraint => 'eu-west-1');
733             my $bucket = $s3->add_bucket ({ bucket => 'new-bucket', location_constraint => 'eu-west-1' });
734              
735             Method creates and returns new bucket.
736              
737             In case of error it reports it and returns C<undef> (refer L</"ERROR HANDLING">).
738              
739             Recognized positional arguments (refer L</"CALLING CONVENTION">)
740              
741             =over
742              
743             =item bucket
744              
745             Required, recognized as positional.
746              
747             The name of the bucket you want to add.
748              
749             =back
750              
751             Recognized optional arguments
752              
753             =over
754              
755             =item acl
756              
757             acl => 'private'
758             acl => Net::Amazon::S3::ACL::Canned->PRIVATE
759             acl => Net::Amazon::S3::ACL::Set->grant_read (email => 'foo@bar.baz')
760              
761             I<Available since v0.94>
762              
763             Set ACL to the newly created bucket. Refer L<Net::Amazon::S3::ACL> for possibilities.
764              
765             =item acl_short (deprecated)
766              
767             I<Deprecated since v0.94>
768              
769             When specified its value is used to populate C<acl> argument (unless it exists).
770              
771             =item location_constraint
772              
773             Optional.
774              
775             Sets the location constraint of the new bucket. If left unspecified, the
776             default S3 datacenter location will be used.
777              
778             This library recognizes regions according Amazon S3 documentation
779              
780             =over
781              
782             =item →
783              
784             L<https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region>
785              
786             =item →
787              
788             L<https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#API_CreateBucket_RequestSyntax>
789              
790             =back
791              
792             =back
793              
794             Provides operation L<CreateBucket|https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html>.
795              
796             =head2 bucket BUCKET
797              
798             # build bucket with guessed region
799             $s3->bucket ('foo');
800             $s3->bucket (bucket => 'foo');
801             $s3->bucket (name => 'foo');
802              
803             # build with explicit region
804             $s3->bucket ('foo', region => 'bar');
805              
806             Returns an (unverified) bucket object from an account. Does no network access.
807              
808             However, when guessing region, C<HeadRegion> operation may be called before
809             first network access.
810              
811             Region is mandatory when using Signature V4 authorization, which is default
812             for AWS. AWS limits number of HTTP requests, see L<https://aws.amazon.com/premiumsupport/knowledge-center/s3-request-limit-avoid-throttling/>
813              
814             =head2 delete_bucket
815              
816             $s3->delete_bucket ($bucket);
817             $s3->delete_bucket (bucket => $bucket);
818              
819             Deletes bucket from account.
820              
821             Returns C<true> if the bucket is successfully deleted.
822              
823             Returns C<false> and reports an error otherwise (refer L</"ERROR HANDLING">)
824              
825             Positional arguments (refer L</"CALLING CONVENTION">)
826              
827             =over
828              
829             =item bucket
830              
831             Required.
832              
833             The name of the bucket or L<Net::Amazon::S3::Bucket> instance you want to delete.
834              
835             =back
836              
837             Provides operation L<"DeleteBucket"|https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucket.html>
838              
839             =head2 list_bucket
840              
841             List all keys in this bucket.
842              
843             Takes a hashref of arguments:
844              
845             MANDATORY
846              
847             =over
848              
849             =item bucket
850              
851             The name of the bucket you want to list keys on
852              
853             =back
854              
855             OPTIONAL
856              
857             =over
858              
859             =item prefix
860              
861             Restricts the response to only contain results that begin with the
862             specified prefix. If you omit this optional argument, the value of
863             prefix for your query will be the empty string. In other words, the
864             results will be not be restricted by prefix.
865              
866             =item delimiter
867              
868             If this optional, Unicode string parameter is included with your
869             request, then keys that contain the same string between the prefix
870             and the first occurrence of the delimiter will be rolled up into a
871             single result element in the CommonPrefixes collection. These
872             rolled-up keys are not returned elsewhere in the response. For
873             example, with prefix="USA/" and delimiter="/", the matching keys
874             "USA/Oregon/Salem" and "USA/Oregon/Portland" would be summarized
875             in the response as a single "USA/Oregon" element in the CommonPrefixes
876             collection. If an otherwise matching key does not contain the
877             delimiter after the prefix, it appears in the Contents collection.
878              
879             Each element in the CommonPrefixes collection counts as one against
880             the MaxKeys limit. The rolled-up keys represented by each CommonPrefixes
881             element do not. If the Delimiter parameter is not present in your
882             request, keys in the result set will not be rolled-up and neither
883             the CommonPrefixes collection nor the NextMarker element will be
884             present in the response.
885              
886             =item max-keys
887              
888             This optional argument limits the number of results returned in
889             response to your query. Amazon S3 will return no more than this
890             number of results, but possibly less. Even if max-keys is not
891             specified, Amazon S3 will limit the number of results in the response.
892             Check the IsTruncated flag to see if your results are incomplete.
893             If so, use the Marker parameter to request the next page of results.
894             For the purpose of counting max-keys, a 'result' is either a key
895             in the 'Contents' collection, or a delimited prefix in the
896             'CommonPrefixes' collection. So for delimiter requests, max-keys
897             limits the total number of list results, not just the number of
898             keys.
899              
900             =item marker
901              
902             This optional parameter enables pagination of large result sets.
903             C<marker> specifies where in the result set to resume listing. It
904             restricts the response to only contain results that occur alphabetically
905             after the value of marker. To retrieve the next page of results,
906             use the last key from the current page of results as the marker in
907             your next request.
908              
909             See also C<next_marker>, below.
910              
911             If C<marker> is omitted,the first page of results is returned.
912              
913             =back
914              
915             Returns undef on error and a hashref of data on success:
916              
917             The hashref looks like this:
918              
919             {
920             bucket => $bucket_name,
921             prefix => $bucket_prefix,
922             common_prefixes => [$prefix1,$prefix2,...]
923             marker => $bucket_marker,
924             next_marker => $bucket_next_available_marker,
925             max_keys => $bucket_max_keys,
926             is_truncated => $bucket_is_truncated_boolean
927             keys => [$key1,$key2,...]
928             }
929              
930             Explanation of bits of that:
931              
932             =over
933              
934             =item common_prefixes
935              
936             If list_bucket was requested with a delimiter, common_prefixes will
937             contain a list of prefixes matching that delimiter. Drill down into
938             these prefixes by making another request with the prefix parameter.
939              
940             =item is_truncated
941              
942             B flag that indicates whether or not all results of your query were
943             returned in this response. If your results were truncated, you can
944             make a follow-up paginated request using the Marker parameter to
945             retrieve the rest of the results.
946              
947             =item next_marker
948              
949             A convenience element, useful when paginating with delimiters. The
950             value of C<next_marker>, if present, is the largest (alphabetically)
951             of all key names and all CommonPrefixes prefixes in the response.
952             If the C<is_truncated> flag is set, request the next page of results
953             by setting C<marker> to the value of C<next_marker>. This element
954             is only present in the response if the C<delimiter> parameter was
955             sent with the request.
956              
957             =back
958              
959             Each key is a hashref that looks like this:
960              
961             {
962             key => $key,
963             last_modified => $last_mod_date,
964             etag => $etag, # An MD5 sum of the stored content.
965             size => $size, # Bytes
966             storage_class => $storage_class # Doc?
967             owner_id => $owner_id,
968             owner_displayname => $owner_name
969             }
970              
971             =head2 list_bucket_all
972              
973             List all keys in this bucket without having to worry about
974             'marker'. This is a convenience method, but may make multiple requests
975             to S3 under the hood.
976              
977             Takes the same arguments as list_bucket.
978              
979             =head2 _perform_operation
980              
981             my $response = $s3->_perform_operation ('Operation' => (
982             # ... operation request parameters
983             ));
984              
985             Internal operation implementation method, takes request construction parameters,
986             performs necessary HTTP requests(s) and returns Response instance.
987              
988             Method takes same named parameters as realted Request class.
989              
990             Method provides available contextual parameters by default (eg s3, bucket)
991              
992             Method invokes contextual error handler.
993              
994             =head1 CALLING CONVENTION
995              
996             I<Available since v0.97> - calling convention extentend
997              
998             In order to make method calls somehow consistent, backward compatible,
999             and extendable, API's methods support multiple ways how to provide their arguments
1000              
1001             =over
1002              
1003             =item plain named arguments (preferred)
1004              
1005             method (named => 'argument', another => 'argument');
1006              
1007             =item trailing configuration hash
1008              
1009             method ({ named => 'argument', another => 'argument' });
1010             method (positional, { named => 'argument', another => 'argument' } );
1011              
1012             Last argument of every method can be configuration hash, treated as additional
1013             named arguments. Can be combined with named arguments.
1014              
1015             =item positional arguments with optional named arguments
1016              
1017             method (positional, named => 'argument', another => 'argument');
1018             method (positional, { named => 'argument', another => 'argument' } );
1019              
1020             For methods supporting mandatory positional arguments additional named
1021             arguments and/or configuration hash is supported.
1022              
1023             Named arguments or configuration hash can specify value of positional
1024             arguments as well removing it from list of required positional arguments
1025             for given call (see example)
1026              
1027             $s3->bucket->add_key ('key', 'value', acl => $acl);
1028             $s3->bucket->add_key ('value', key => 'key', acl => $acl);
1029             $s3->bucket->add_key (key => 'key', value => 'value', acl => $acl);
1030              
1031             =back
1032              
1033             =head1 ERROR HANDLING
1034              
1035             L<Net::Amazon::S3> supports pluggable error handling via
1036             L<Net::Amazon::S3::Error::Handler>.
1037              
1038             When response ends up with an error, every method reports it, and in case it
1039             receives control back (no exception), it returns C<undef>.
1040              
1041             Default error handling for L<Net::Amazon::S3> is L<Net::Amazon::S3::Error::Handler::Legacy>
1042             which (mostly) sets C<err> and C<errstr>.
1043              
1044             =head1 LICENSE
1045              
1046             This module contains code modified from Amazon that contains the
1047             following notice:
1048              
1049             # This software code is made available "AS IS" without warranties of any
1050             # kind. You may copy, display, modify and redistribute the software
1051             # code either by itself or as incorporated into your code; provided that
1052             # you do not remove any proprietary notices. Your use of this software
1053             # code is at your own risk and you waive any claim against Amazon
1054             # Digital Services, Inc. or its affiliates with respect to your use of
1055             # this software code. (c) 2006 Amazon Digital Services, Inc. or its
1056             # affiliates.
1057              
1058             =head1 TESTING
1059              
1060             Testing S3 is a tricky thing. Amazon wants to charge you a bit of
1061             money each time you use their service. And yes, testing counts as using.
1062             Because of this, the application's test suite skips anything approaching
1063             a real test unless you set these three environment variables:
1064              
1065             =over
1066              
1067             =item AMAZON_S3_EXPENSIVE_TESTS
1068              
1069             Doesn't matter what you set it to. Just has to be set
1070              
1071             =item AWS_ACCESS_KEY_ID
1072              
1073             Your AWS access key
1074              
1075             =item AWS_ACCESS_KEY_SECRET
1076              
1077             Your AWS sekkr1t passkey. Be forewarned that setting this environment variable
1078             on a shared system might leak that information to another user. Be careful.
1079              
1080             =back
1081              
1082             =head1 AUTHOR
1083              
1084             Leon Brocard <acme@astray.com> and unknown Amazon Digital Services programmers.
1085              
1086             Brad Fitzpatrick <brad@danga.com> - return values, Bucket object
1087              
1088             Pedro Figueiredo <me@pedrofigueiredo.org> - since 0.54
1089              
1090             Branislav Zahradník <barney@cpan.org> - since v0.81
1091              
1092             =head1 SEE ALSO
1093              
1094             L<Net::Amazon::S3::Bucket>
1095              
1096             =head1 AUTHOR
1097              
1098             Branislav Zahradník <barney@cpan.org>
1099              
1100             =head1 COPYRIGHT AND LICENSE
1101              
1102             This software is copyright (c) 2022 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.
1103              
1104             This is free software; you can redistribute it and/or modify it under
1105             the same terms as the Perl 5 programming language system itself.
1106              
1107             =cut