| 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.98'; |
|
4
|
96
|
|
|
96
|
|
9540
|
use Moose 0.85; |
|
|
96
|
|
|
|
|
7626845
|
|
|
|
96
|
|
|
|
|
1101
|
|
|
5
|
96
|
|
|
96
|
|
700567
|
use HTTP::Status qw(status_message); |
|
|
96
|
|
|
|
|
46101
|
|
|
|
96
|
|
|
|
|
7795
|
|
|
6
|
96
|
|
|
96
|
|
11809
|
use MooseX::StrictConstructor 0.16; |
|
|
96
|
|
|
|
|
503185
|
|
|
|
96
|
|
|
|
|
745
|
|
|
7
|
96
|
|
|
96
|
|
445879
|
use Moose::Util::TypeConstraints; |
|
|
96
|
|
|
|
|
342
|
|
|
|
96
|
|
|
|
|
1085
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
96
|
|
|
96
|
|
277470
|
use Net::Amazon::S3::Error::Handler::Confess; |
|
|
96
|
|
|
|
|
331
|
|
|
|
96
|
|
|
|
|
63837
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
type 'Etag' => where { $_ =~ /^[a-z0-9]{32}(?:-\d+)?$/ }; |
|
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
|
18
|
my $self = shift; |
|
62
|
5
|
|
|
|
|
176
|
my $s3 = $self->s3; |
|
63
|
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
32
|
my $response = $self->_perform_operation ( |
|
65
|
|
|
|
|
|
|
'Net::Amazon::S3::Operation::Buckets::List', |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
22
|
return unless $response->is_success; |
|
69
|
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
57
|
my $owner_id = $response->owner_id; |
|
71
|
2
|
|
|
|
|
12
|
my $owner_display_name = $response->owner_displayname; |
|
72
|
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
5
|
my @buckets; |
|
74
|
2
|
|
|
|
|
13
|
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
|
|
|
|
|
135
|
owner_id => $owner_id, |
|
80
|
|
|
|
|
|
|
owner_display_name => $owner_display_name, |
|
81
|
|
|
|
|
|
|
); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
|
84
|
2
|
|
|
|
|
28
|
return @buckets; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub create_bucket { |
|
88
|
17
|
|
|
17
|
1
|
68
|
my ( $self, %conf ) = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $bucket = $self->bucket_class->new( |
|
91
|
|
|
|
|
|
|
client => $self, |
|
92
|
|
|
|
|
|
|
name => $conf{name}, |
|
93
|
17
|
|
|
|
|
640
|
); |
|
94
|
17
|
|
|
|
|
106
|
$bucket->_create(%conf); |
|
95
|
6
|
|
|
|
|
628
|
return $bucket; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub bucket { |
|
99
|
120
|
|
|
120
|
1
|
542
|
my ( $self, %conf ) = @_; |
|
100
|
120
|
|
|
|
|
4881
|
return $self->bucket_class->new( |
|
101
|
|
|
|
|
|
|
client => $self, |
|
102
|
|
|
|
|
|
|
%conf, |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _perform_operation { |
|
107
|
138
|
|
|
138
|
|
638
|
my ($self, $operation, %params) = @_; |
|
108
|
|
|
|
|
|
|
|
|
109
|
138
|
|
|
|
|
3928
|
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.98 |
|
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
|
|
|
|
|
|
|
=head1 METHODS |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 new |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L<Net::Amazon::S3::Client> can be constructed two ways. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Historically it wraps S3 API instance |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
use Net::Amazon::S3::Client; |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
my $client = Net::Amazon::S3::Client->new ( |
|
212
|
|
|
|
|
|
|
s3 => .... # Net::Amazon::S3 instance |
|
213
|
|
|
|
|
|
|
); |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 new (since v0.92) |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Since v0.92 explicit creation of S3 API instance is no longer necessary. |
|
218
|
|
|
|
|
|
|
L<Net::Amazon::S3::Client>'s constructor accepts same parameters as L<Net::Amazon::S3> |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
use Net::Amazon::S3::Client v0.92; |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $client = Net::Amazon::S3::Client->new ( |
|
223
|
|
|
|
|
|
|
aws_access_key_id => ..., |
|
224
|
|
|
|
|
|
|
aws_secret_access_key => ..., |
|
225
|
|
|
|
|
|
|
..., |
|
226
|
|
|
|
|
|
|
); |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 buckets |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# list all my buckets |
|
231
|
|
|
|
|
|
|
# returns a list of L<Net::Amazon::S3::Client::Bucket> objects |
|
232
|
|
|
|
|
|
|
my @buckets = $client->buckets; |
|
233
|
|
|
|
|
|
|
foreach my $bucket (@buckets) { |
|
234
|
|
|
|
|
|
|
print $bucket->name . "\n"; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 create_bucket |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# create a new bucket |
|
240
|
|
|
|
|
|
|
# returns a L<Net::Amazon::S3::Client::Bucket> object |
|
241
|
|
|
|
|
|
|
my $bucket = $client->create_bucket( |
|
242
|
|
|
|
|
|
|
name => $bucket_name, |
|
243
|
|
|
|
|
|
|
acl_short => 'private', |
|
244
|
|
|
|
|
|
|
location_constraint => 'us-east-1', |
|
245
|
|
|
|
|
|
|
); |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 bucket |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# or use an existing bucket |
|
250
|
|
|
|
|
|
|
# returns a L<Net::Amazon::S3::Client::Bucket> object |
|
251
|
|
|
|
|
|
|
my $bucket = $client->bucket( name => $bucket_name ); |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head2 bucket_class |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# returns string "Net::Amazon::S3::Client::Bucket" |
|
256
|
|
|
|
|
|
|
# subclasses will want to override this. |
|
257
|
|
|
|
|
|
|
my $bucket_class = $client->bucket_class |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 AUTHOR |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Branislav Zahradník <barney@cpan.org> |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník. |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
268
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=cut |