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