Amazon/S3/BucketV2.pm

filter: Statementstmt 97.3% 110 / 113 Branchbran 77.2% 17 / 22 Conditioncond 56.5% 13 / 23 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 94.4% 17 / 18 Podpod 50.0% 2 / 4 totaltotal 83.5% 162 / 194 CC 22 SCAR 21.9
CC
22
Cov
89%
send_request
18.9
create_methods
4.0
__ANON__
4.0
CRAP 9.0
« Amazon/S3/Constants.pm ↑ Summary Amazon/S3/Signature/V4.pm »
1 package Amazon::S3::BucketV2;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use Amazon::S3::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Amazon::S3::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use List::Util qw(pairs);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 ▶use parent qw(Amazon::S3::Bucket);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 13 our $VERSION = '2.1.4'; ## no critic (RequireInterpolation)
18  
19 ######################################################################
20 13 our @GET_OBJECT_METHODS = (
21 ######################################################################
22 get_object_acl => 'acl',
23 get_object_attributes => 'attributes',
24 get_object_legal_hold => 'legal-hold',
25 get_object_lock_configuration => 'object-lock',
26 get_object_retention => 'retention',
27 get_object_tagging => 'tagging',
28 get_object_torrent => 'torrent',
29 get_public_access_block => 'publicAccessBlock',
30 );
31  
32 13 create_methods(
33 type => 'object',
34 method => 'GET',
35 method_def => \@GET_OBJECT_METHODS
36 );
37  
38 ######################################################################
39 13 our @HEAD_OBJECT_METHODS = ( get_object_head => 'head', );
40 ######################################################################
41  
42 13 create_methods(
43 type => 'object',
44 method => 'HEAD',
45 method_def => [ head_object => $EMPTY ]
46 );
47  
48 13 create_methods(
49 type => 'bucket',
50 method => 'HEAD',
51 method_def => [ head_bucket => $EMPTY ]
52 );
53  
54 ######################################################################
55 13 our @GET_BUCKET_METHODS = (
56 ######################################################################
57 get_bucket_accelerate_configuration => 'accelerate',
58 get_bucket_acl => 'acl',
59 get_bucket_analytics => 'analytics',
60 get_bucket_cors => 'cors',
61 get_bucket_encryption => 'encryption',
62 get_bucket_intelligent_tiering_configuration => 'intelligent_tiering',
63 get_bucket_inventory_configuration => 'inventory',
64 get_bucket_lifecycle_configuration => 'lifecycle',
65 get_bucket_location => 'location',
66 get_bucket_logging => 'logging',
67 get_bucket_metrics_configuration => 'metrics',
68 get_bucket_notification_configuration => 'notification',
69 get_bucket_ownership_controls => 'ownershipControls',
70 get_bucket_policy => 'policy',
71 get_bucket_policy_status => 'policyStatus',
72 get_bucket_replication => 'replication',
73 get_bucket_request_payment => 'requestPayment',
74 get_bucket_tagging => 'tagging',
75 get_bucket_versioning => 'versioning',
76 get_bucket_website => 'website',
77 );
78  
79 13 create_methods(
80 type => 'bucket',
81 method => 'GET',
82 method_def => \@GET_BUCKET_METHODS,
83 );
84  
85 #######################################################################
86 13 our @LIST_BUCKET_METHODS = (
87 #######################################################################
88 list_multipart_uploads => 'uploads',
89 list_object_versions => 'versions',
90 );
91  
92 13 create_methods(
93 type => 'bucket',
94 method => 'GET',
95 method_def => \@LIST_BUCKET_METHODS,
96 );
97  
98 #######################################################################
99 13 our @PUT_BUCKET_METHODS = (
100 #######################################################################
101 put_bucket_intelligent_tiering_configuration => 'intelligent-tiering',
102 put_bucket_cors => 'cors',
103 put_bucket_replication_configuration => 'replication',
104 put_bucket_versioning => 'versioning',
105 put_bucket_encryption => 'encryption',
106 put_bucket_lifecycle_configuration => 'lifecycle',
107 put_bucket_lifecycle => 'lifecycle',
108 put_bucket_tagging => 'tagging',
109 );
110  
111 13 create_methods(
112 type => 'bucket',
113 method => 'PUT',
114 method_def => \@PUT_BUCKET_METHODS
115 );
116  
117 ######################################################################
118 our @PUT_OBJECT_METHODS = (
119 #######################################################################
120 put_object => $EMPTY,
121 put_object_acl => 'acl',
122 put_object_tagging => 'tagging',
123 put_object_retention => 'retention',
124 put_object_legal_hold => 'legal-hold',
125 put_object_lock_configuration => 'lock-object',
126 put_public_access_block => 'publicAccessBlock',
127 13 ▶ restore_object => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
128 13 return { method => 'POST', api => 'restore' };
129 },
130 13 upload_part => $EMPTY,
131 upload_part_copy => $EMPTY,
132 );
133  
134 13 create_methods(
135 type => 'object',
136 method => 'PUT',
137 method_def => \@PUT_OBJECT_METHODS,
138 );
139  
140 ######################################################################
141 our @DELETE_OBJECT_METHODS = (
142 ######################################################################
143 abort_multipart_upload => $EMPTY,
144 delete_object => $EMPTY,
145 13 ▶ delete_objects => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
146 13 return { method => 'POST', api => 'delete' };
147 },
148 13 delete_object_tagging => 'tagging',
149 );
150  
151 13 create_methods(
152 type => 'object',
153 method => 'DELETE',
154 method_def => \@DELETE_OBJECT_METHODS,
155 );
156  
157 ######################################################################
158 13 our @DELETE_BUCKET_METHODS = (
159 ######################################################################
160 delete_bucket => $EMPTY,
161 delete_bucket_analytics_configuration => 'analytics',
162 delete_bucket_cors => 'cors',
163 delete_bucket_encryption => 'encryption',
164 delete_bucket_intelligent_tiering => 'intelligent-tiering',
165 delete_bucket_inventory_configuration => 'inventory',
166 delete_bucket_lifecycle => 'lifecycle',
167 delete_bucket_metrics_configuration => 'metrics',
168 delete_bucket_ownership_controls => 'ownershipControls',
169 delete_bucket_policy => 'policy',
170 delete_bucket_replication => 'replication',
171 delete_bucket_tagging => 'tagging',
172 delete_bucket_website => 'website',
173 delete_public_access_block => 'publicAccessBlock',
174 );
175  
176 13 create_methods(
177 type => 'bucket',
178 method => 'DELETE',
179 method_def => \@DELETE_BUCKET_METHODS
180 );
181  
182 ########################################################################
183 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
184 ########################################################################
185 0 my ( $class, @args ) = @_;
186  
187 0 return $class->SUPER::new(@args);
188 }
189  
190 ########################################################################
191 950 ▶sub to_camel_case {
Subroutine to_camel_case: called CC=1 SCAR=0.0
Pod undocumented
192 ########################################################################
193 950 my ($method) = @_;
194  
195 950 return join $EMPTY, map { ucfirst $_ } split /_/xsm, $method;
196 }
197  
198 ########################################################################
199 # send_request()
200 ########################################################################
201 # This is a general purpose method to send requests that may include an
202 # XML payload. These requests may also accept headers or query string
203 # parameters.
204 #
205 # args is a hash ref or list of key/value pairs
206 # api => name of the API to invoke (example: 'versioning')
207 # content_key => optional root element for XML serialzation
208 # headers => optional headers - create a Content-MD5 key in the headers
209 # object if you want to add the MD5 value
210 # bucket => optional bucket name
211 # key => optional key value for APIs that accept a key
212 # data => optional object that will be converted to an XML payload
213 # method => HTTP method
214 #
215 # NOTES:
216 # 1. If the 'data' object is included, the default method is 'PUT'
217 # 2. If no 'data' object is included, the default method is 'GET'
218 # 3. If 'content_key' is not provided when including a 'data' object
219 # the method will attempt to guess the root element (content_key)
220 # when serializing the data object to XML. If you include
221 # additional elements to be used as query string parameters,
222 # you should specify 'content_key'..
223 ########################################################################
224 7 ▶sub send_request {
Subroutine send_request: called CC=16 SCAR=29.4
Pod documented
225 ########################################################################
226 7 my ( $self, @args ) = @_;
227  
228 7 my $parameters = get_parameters(@args);
229  
230 7 my $account = $self->account;
231  
232 7 my $headers = delete $parameters->{headers};
233 7 ▶ $headers //= {};
Condition100%2/2
$headers //= {}
l!l
16
MC/DC100%1/1
$headers //= {}
$headers
Truth table100%2/2
A
A= $headers
Aresult
11
00
234  
235 7 my $bucket = delete $parameters->{bucket};
236  
237 7 ▶ $bucket //= $self->bucket;
Condition33%1/3
$bucket //= $self->bucket
l!l&&r!l&&!r
070
MC/DC0%0/2
$bucket //= $self->bucket
$bucket $self->bucket
Truth table33%1/3
A //= B
A= $bucketB= $self->bucket
ABresult
1X1
011
000
238  
239 7 ▶ croak 'no bucket'
Branch: 1 branch
BranchTrueFalseTotal
unless $bucket 0 7 7
240 if !$bucket;
241  
242 7 ▶ my $key = delete $parameters->{key} // $EMPTY;
Condition66%2/3
delete $parameters->{"key"} // $Amazon::S3::BucketV2::EMPTY
l!l&&r!l&&!r
430
MC/DC0%0/2
delete $parameters->{"key"} // $Amazon::S3::BucketV2::EMPTY
delete $parameters->{"key"} $Amazon::S3::BucketV2::EMPTY
Truth table66%2/3
A // B
A= delete $parameters->{"key"}B= $Amazon::S3::BucketV2::EMPTY
ABresult
1X1
011
000
243  
244 7 my $api = delete $parameters->{api};
245  
246 7 ▶ croak 'no api'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $api 0 7 7
247 if !defined $api;
248  
249 7 my $path = delete $parameters->{path};
250  
251 7 my $method = delete $parameters->{method};
252  
253 # see if we need to send an XML payload
254 7 my $data = delete $parameters->{data};
255  
256 7 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 2 5 7
257 2 my $content_key = delete $parameters->{content_key};
258  
259 # if we are sending data, include MD5 by default
260 2 my $md5 = delete $parameters->{md5};
261 2 ▶ $md5 //= $TRUE;
Condition33%1/3
$md5 //= $Amazon::S3::BucketV2::TRUE
l!l&&r!l&&!r
020
MC/DC0%0/2
$md5 //= $Amazon::S3::BucketV2::TRUE
$md5 $Amazon::S3::BucketV2::TRUE
Truth table33%1/3
A //= B
A= $md5B= $Amazon::S3::BucketV2::TRUE
ABresult
1X1
011
000
262  
263 2 ▶ if ( !$content_key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content_key) 2 0 2
264 2 ($content_key) = keys %{$parameters};
265 }
266  
267 2 $data = create_xml_request($data);
268  
269 2 ▶ if ( $md5 || exists $headers->{'Content-MD5'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($md5 or exists $headers->{"Content-MD5"}) 2 0 2
Condition33%1/3
$md5 or exists $headers->{"Content-MD5"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$md5 or exists $headers->{"Content-MD5"}
$md5 exists $headers->{"Content-MD5"}
Truth table33%1/3
A or B
A= $md5B= exists $headers->{"Content-MD5"}
ABresult
1X1
011
000
270 2 set_md5_header( data => $data, headers => $headers );
271 }
272 }
273  
274 # create the URI from bucket, key, api and possibly additional parameters
275 7 ▶ $path //= sprintf '%s/%s?%s', $bucket, $key, $api;
Condition50%1/2
$path //= sprintf('%s/%s?%s', $bucket, $key, $api)
l!l
07
MC/DC0%0/1
$path //= sprintf('%s/%s?%s', $bucket, $key, $api)
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
276  
277 7 ▶ if ( keys %{$parameters} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$parameters;}) 2 5 7
278 2 my $query_string = create_query_string( %{$parameters} );
279  
280 2 ▶ if ( $path !~ /[?]$/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ /[?]$/msx) 0 2 2
281 0 $query_string = "&$query_string";
282 }
283  
284 2 $path .= $query_string;
285 }
286  
287 7 ▶ return $account->send_request(
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 2 5 7
Condition50%1/2
$method // "GET"
l!l
70
MC/DC0%0/1
$method // "GET"
$method
Truth table50%1/2
A
A= $method
Aresult
11
00
288 { region => $self->region,
289 method => $method // 'GET',
290 path => $path,
291 headers => $headers,
292 $data ? ( data => $data ) : (),
293 }
294 );
295 }
296  
297 ########################################################################
298 117 ▶sub create_methods {
Subroutine create_methods: called CC=4 SCAR=13.9
Pod undocumented
299 ########################################################################
300 117 my (%args) = @_;
301  
302 117 my ( $type, $method, $method_def ) = @args{qw( type method method_def)};
303  
304 13 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
305  
306 117 foreach my $p ( pairs @{$method_def} ) {
307 884 my ( $sub_name, $api ) = @{$p};
308  
309 884 my $api_method = $method;
310  
311 884 ▶ if ( ref($api) && reftype($api) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $api and builtin::reftype($api) eq "CODE") 26 858 884
Condition66%2/3
ref $api and builtin::reftype($api) eq "CODE"
!ll&&!rl&&r
858026
MC/DC50%1/2
ref $api and builtin::reftype($api) eq "CODE"
ref $api builtin::reftype($api) eq "CODE"
Truth table66%2/3
A and B
A= ref $apiB= builtin::reftype($api) eq "CODE"
ABresult
0X0
100
111
312 26 my $api_params = $api->();
313 26 ( $api_method, $api ) = @{$api_params}{qw(method api)};
314 }
315  
316 7 ▶ my $anon = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
317 7 my ( $self, %args ) = @_;
318  
319 7 my ( $key, $body, $uri_params, $headers ) = @args{qw(key body uri_param headers)};
320 7 ▶ $uri_params //= {};
Condition100%2/2
$uri_params //= {}
l!l
25
MC/DC100%1/1
$uri_params //= {}
$uri_params
Truth table100%2/2
A
A= $uri_params
Aresult
11
00
321  
322 return $self->send_request(
323 method => $api_method,
324 api => $api,
325 headers => $headers,
326 $key ? ( key => $key ) : (),
327 $body ? ( data => $body ) : (),
328 7 ▶ %{$uri_params},
Branch: 2 branches
BranchTrueFalseTotal
$key ? : 4 3 7
$body ? : 2 5 7
329 );
330 884 };
331  
332 884 $sub_name = sprintf 'Amazon::S3::BucketV2::%s', to_camel_case($sub_name);
333 884 *{$sub_name} = $anon;
334 }
335  
336 117 return;
337 }
338  
339 13 1;
340  
341 __END__
« Amazon/S3/Constants.pm ↑ Summary Amazon/S3/Signature/V4.pm »