line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::S3::Client; |
2
|
|
|
|
|
|
|
# ABSTRACT: An easy-to-use Amazon S3 client |
3
|
|
|
|
|
|
|
$Net::Amazon::S3::Client::VERSION = '0.99'; |
4
|
99
|
|
|
99
|
|
12144
|
use Moose 0.85; |
|
99
|
|
|
|
|
8366732
|
|
|
99
|
|
|
|
|
1129
|
|
5
|
99
|
|
|
99
|
|
703335
|
use HTTP::Status qw(status_message); |
|
99
|
|
|
|
|
53478
|
|
|
99
|
|
|
|
|
7869
|
|
6
|
99
|
|
|
99
|
|
11255
|
use MooseX::StrictConstructor 0.16; |
|
99
|
|
|
|
|
543067
|
|
|
99
|
|
|
|
|
755
|
|
7
|
99
|
|
|
99
|
|
454396
|
use Moose::Util::TypeConstraints; |
|
99
|
|
|
|
|
416
|
|
|
99
|
|
|
|
|
1023
|
|
8
|
|
|
|
|
|
|
|
9
|
99
|
|
|
99
|
|
242762
|
use Net::Amazon::S3; |
|
99
|
|
|
|
|
317
|
|
|
99
|
|
|
|
|
3677
|
|
10
|
99
|
|
|
99
|
|
34279
|
use Net::Amazon::S3::Constraint::Etag; |
|
99
|
|
|
|
|
288
|
|
|
99
|
|
|
|
|
3487
|
|
11
|
99
|
|
|
99
|
|
53776
|
use Net::Amazon::S3::Error::Handler::Confess; |
|
99
|
|
|
|
|
342
|
|
|
99
|
|
|
|
|
56703
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 's3' => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
isa => 'Net::Amazon::S3', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
handles => [ |
18
|
|
|
|
|
|
|
'ua', |
19
|
|
|
|
|
|
|
], |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
default => sub { $_[0]->error_handler_class->new (s3 => $_[0]->s3) }, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has bucket_class => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
init_arg => undef, |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
default => 'Net::Amazon::S3::Client::Bucket', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
around BUILDARGS => sub { |
42
|
|
|
|
|
|
|
my ($orig, $class) = (shift, shift); |
43
|
|
|
|
|
|
|
my $args = $class->$orig (@_); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
unless (exists $args->{s3}) { |
46
|
|
|
|
|
|
|
my $error_handler_class = delete $args->{error_handler_class}; |
47
|
|
|
|
|
|
|
my $error_handler = delete $args->{error_handler}; |
48
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
$args; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub buckets { |
61
|
5
|
|
|
5
|
1
|
12
|
my $self = shift; |
62
|
5
|
|
|
|
|
180
|
my $s3 = $self->s3; |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
40
|
my $response = $self->_perform_operation ( |
65
|
|
|
|
|
|
|
'Net::Amazon::S3::Operation::Buckets::List', |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
19
|
return unless $response->is_success; |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
55
|
my $owner_id = $response->owner_id; |
71
|
2
|
|
|
|
|
10
|
my $owner_display_name = $response->owner_displayname; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
3
|
my @buckets; |
74
|
2
|
|
|
|
|
9
|
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
|
|
|
|
|
145
|
owner_id => $owner_id, |
80
|
|
|
|
|
|
|
owner_display_name => $owner_display_name, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
2
|
|
|
|
|
27
|
return @buckets; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub create_bucket { |
88
|
17
|
|
|
17
|
1
|
69
|
my ( $self, %conf ) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $bucket = $self->bucket_class->new( |
91
|
|
|
|
|
|
|
client => $self, |
92
|
|
|
|
|
|
|
name => $conf{name}, |
93
|
17
|
|
|
|
|
762
|
); |
94
|
17
|
|
|
|
|
110
|
$bucket->_create(%conf); |
95
|
6
|
|
|
|
|
801
|
return $bucket; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub bucket { |
99
|
126
|
|
|
126
|
1
|
529
|
my ( $self, %conf ) = @_; |
100
|
126
|
|
|
|
|
5048
|
return $self->bucket_class->new( |
101
|
|
|
|
|
|
|
client => $self, |
102
|
|
|
|
|
|
|
%conf, |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _perform_operation { |
107
|
144
|
|
|
144
|
|
657
|
my ($self, $operation, %params) = @_; |
108
|
|
|
|
|
|
|
|
109
|
144
|
|
|
|
|
4089
|
return $self->s3->_perform_operation ( |
110
|
|
|
|
|
|
|
$operation, |
111
|
|
|
|
|
|
|
error_handler => $self->error_handler, |
112
|
|
|
|
|
|
|
%params |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=pod |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=encoding UTF-8 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 NAME |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Net::Amazon::S3::Client - An easy-to-use Amazon S3 client |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 VERSION |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
version 0.99 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SYNOPSIS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Build Client instance |
135
|
|
|
|
|
|
|
my $client = Net::Amazon::S3::Client->new ( |
136
|
|
|
|
|
|
|
# accepts all Net::Amazon::S3's arguments |
137
|
|
|
|
|
|
|
aws_access_key_id => $aws_access_key_id, |
138
|
|
|
|
|
|
|
aws_secret_access_key => $aws_secret_access_key, |
139
|
|
|
|
|
|
|
retry => 1, |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# or reuse an existing S3 connection |
143
|
|
|
|
|
|
|
my $client = Net::Amazon::S3::Client->new (s3 => $s3); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# list all my buckets |
146
|
|
|
|
|
|
|
# returns a list of L<Net::Amazon::S3::Client::Bucket> objects |
147
|
|
|
|
|
|
|
my @buckets = $client->buckets; |
148
|
|
|
|
|
|
|
foreach my $bucket (@buckets) { |
149
|
|
|
|
|
|
|
print $bucket->name . "\n"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# create a new bucket |
153
|
|
|
|
|
|
|
# returns a L<Net::Amazon::S3::Client::Bucket> object |
154
|
|
|
|
|
|
|
my $bucket = $client->create_bucket( |
155
|
|
|
|
|
|
|
name => $bucket_name, |
156
|
|
|
|
|
|
|
acl_short => 'private', |
157
|
|
|
|
|
|
|
location_constraint => 'us-east-1', |
158
|
|
|
|
|
|
|
); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# or use an existing bucket |
161
|
|
|
|
|
|
|
# returns a L<Net::Amazon::S3::Client::Bucket> object |
162
|
|
|
|
|
|
|
my $bucket = $client->bucket( name => $bucket_name ); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DESCRIPTION |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The L<Net::Amazon::S3> module was written when the Amazon S3 service |
167
|
|
|
|
|
|
|
had just come out and it is a light wrapper around the APIs. Some |
168
|
|
|
|
|
|
|
bad API decisions were also made. The |
169
|
|
|
|
|
|
|
L<Net::Amazon::S3::Client>, L<Net::Amazon::S3::Client::Bucket> and |
170
|
|
|
|
|
|
|
L<Net::Amazon::S3::Client::Object> classes are designed after years |
171
|
|
|
|
|
|
|
of usage to be easy to use for common tasks. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
These classes throw an exception when a fatal error occurs. It |
174
|
|
|
|
|
|
|
also is very careful to pass an MD5 of the content when uploaded |
175
|
|
|
|
|
|
|
to S3 and check the resultant ETag. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
WARNING: This is an early release of the Client classes, the APIs |
178
|
|
|
|
|
|
|
may change. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=for test_synopsis no strict 'vars' |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item s3 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L<< Net::Amazon::S3 >> instance |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item error_handler_class |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Error handler class name (package name), see L<< Net::Amazon::S3::Error::Handler >> |
193
|
|
|
|
|
|
|
for more. Overrides one available in C<s3>. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Default: L<< Net::Amazon::S3::Error::Handler::Confess >> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item error_handler |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Instance of error handler class. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 METHODS |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 new |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L<Net::Amazon::S3::Client> can be constructed two ways. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Historically it wraps S3 API instance |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
use Net::Amazon::S3::Client; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
my $client = Net::Amazon::S3::Client->new ( |
214
|
|
|
|
|
|
|
s3 => .... # Net::Amazon::S3 instance |
215
|
|
|
|
|
|
|
); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 new (since v0.92) |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Since v0.92 explicit creation of S3 API instance is no longer necessary. |
220
|
|
|
|
|
|
|
L<Net::Amazon::S3::Client>'s constructor accepts same parameters as L<Net::Amazon::S3> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
use Net::Amazon::S3::Client v0.92; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
my $client = Net::Amazon::S3::Client->new ( |
225
|
|
|
|
|
|
|
aws_access_key_id => ..., |
226
|
|
|
|
|
|
|
aws_secret_access_key => ..., |
227
|
|
|
|
|
|
|
..., |
228
|
|
|
|
|
|
|
); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 buckets |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# list all my buckets |
233
|
|
|
|
|
|
|
# returns a list of L<Net::Amazon::S3::Client::Bucket> objects |
234
|
|
|
|
|
|
|
my @buckets = $client->buckets; |
235
|
|
|
|
|
|
|
foreach my $bucket (@buckets) { |
236
|
|
|
|
|
|
|
print $bucket->name . "\n"; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 create_bucket |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# create a new bucket |
242
|
|
|
|
|
|
|
# returns a L<Net::Amazon::S3::Client::Bucket> object |
243
|
|
|
|
|
|
|
my $bucket = $client->create_bucket( |
244
|
|
|
|
|
|
|
name => $bucket_name, |
245
|
|
|
|
|
|
|
acl_short => 'private', |
246
|
|
|
|
|
|
|
location_constraint => 'us-east-1', |
247
|
|
|
|
|
|
|
); |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 bucket |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# or use an existing bucket |
252
|
|
|
|
|
|
|
# returns a L<Net::Amazon::S3::Client::Bucket> object |
253
|
|
|
|
|
|
|
my $bucket = $client->bucket( name => $bucket_name ); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 bucket_class |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# returns string "Net::Amazon::S3::Client::Bucket" |
258
|
|
|
|
|
|
|
# subclasses will want to override this. |
259
|
|
|
|
|
|
|
my $bucket_class = $client->bucket_class |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 AUTHOR |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Branislav Zahradník <barney@cpan.org> |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
270
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |