Shared/Examples/Net/Amazon/S3/API.pm

filter: Statementstmt 100% 84 / 84 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 30 / 30 Podpod 0.0% 0 / 18 totaltotal 84.6% 121 / 143 SCAR 19.5
CC
7
Cov
98%
operation_object_create
6.0
_default_with_api
2.0
BEGIN
1.0
CRAP 7.0
« Shared/Examples/Net/Amazon/S3/Client.pm ↑ Summary Net/Amazon/S3/Request/Role/XML/Content.pm »
1 package Shared::Examples::Net::Amazon::S3::API;
2 # ABSTRACT: used for testing and as example
3 90 $Shared::Examples::Net::Amazon::S3::API::VERSION = '0.99';
4 90 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 90 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 90 ▶use parent qw[ Exporter::Tiny ];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 90 ▶use Hash::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 90 ▶use Test::Deep;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 90 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 90 ▶use Net::Amazon::S3;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 90 ▶use Shared::Examples::Net::Amazon::S3;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 90 our @EXPORT_OK = (
17 qw[ expect_signed_uri ],
18 qw[ expect_api_list_all_my_buckets ],
19 qw[ expect_api_bucket_acl_get ],
20 qw[ expect_api_bucket_acl_set ],
21 qw[ expect_api_bucket_create ],
22 qw[ expect_api_bucket_delete ],
23 qw[ expect_api_bucket_objects_delete ],
24 qw[ expect_api_bucket_objects_list ],
25 qw[ expect_api_bucket_tags_add ],
26 qw[ expect_api_bucket_tags_delete ],
27 qw[ expect_api_object_acl_get ],
28 qw[ expect_api_object_acl_set ],
29 qw[ expect_api_object_create ],
30 qw[ expect_api_object_delete ],
31 qw[ expect_api_object_fetch ],
32 qw[ expect_api_object_head ],
33 qw[ expect_api_object_tags_add ],
34 qw[ expect_api_object_tags_delete ],
35 qw[ with_fixture ],
36 );
37  
38 90 *with_fixture = *Shared::Examples::Net::Amazon::S3::with_fixture;
39  
40 sub _exporter_expand_sub {
41 20 ▶ my ($self, $name, $args, $globals) = @_;
Subroutine _exporter_expand_sub: called CC=1 SCAR=0.0
42  
43 20 my $s3_operation = $name;
44 20 $s3_operation =~ s/_api_/_operation_/;
45  
46 20 ▶ return +( $name => eval <<"GEN_SUB" );
Subroutine __ANON__: called CC=1 SCAR=0.0
47 sub {
48 push \@_, -shared_examples => __PACKAGE__;
49 goto \\& Shared::Examples::Net::Amazon::S3::$s3_operation;
50 }
51 GEN_SUB
52 }
53  
54 sub _default_with_api {
55 187 ▶ my ($self, $params) = @_;
Subroutine _default_with_api: called CC=2 SCAR=7.1
56  
57 187 ▶ $params->{with_s3} ||= Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2 ();
Condition66%2/3
$params->{"with_s3"} ||= Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2()
l!l&&r!l&&!r
61810
MC/DC0%0/2
$params->{"with_s3"} ||= Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2()
$params->{"with_s3"} Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2()
Truth table66%2/3
A ||= B
A= $params->{"with_s3"}B= Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2()
ABresult
1X1
011
000
58 }
59  
60 sub _mock_http_response {
61 107 ▶ my (undef, $api, %params) = @_;
Subroutine _mock_http_response: called CC=1 SCAR=0.0
62  
63 107 Shared::Examples::Net::Amazon::S3->s3_api_mock_http_response (
64 $api,
65 %params,
66 )
67 }
68  
69 sub expect_signed_uri {
70 4 ▶ my ($title, %params) = @_;
Subroutine expect_signed_uri: called CC=1 SCAR=0.0
Pod undocumented
71  
72 4 local $Test::Builder::Level = $Test::Builder::Level + 1;
73  
74 4 Hash::Util::lock_keys %params,
75 qw[ with_s3 ],
76 qw[ with_bucket ],
77 qw[ with_region ],
78 qw[ with_key ],
79 qw[ with_expire_at ],
80 qw[ with_method ],
81 qw[ expect_uri ],
82 ;
83  
84 my $got = Net::Amazon::S3::Bucket
85 ->new ({
86 account => $params{with_s3},
87 bucket => $params{with_bucket},
88 region => $params{with_region},
89 })
90 ->query_string_authentication_uri (
91 $params{with_key},
92 $params{with_expire_at},
93 (method => $params{with_method}) x!! exists $params{with_method},
94 4 );
95  
96 4 cmp_deeply $got, $params{expect_uri}, $title;
97 }
98  
99 sub operation_list_all_my_buckets {
100 4 ▶ my ($self, %params) = @_;
Subroutine operation_list_all_my_buckets: called CC=1 SCAR=0.0
Pod undocumented
101  
102 4 $self->buckets;
103 }
104  
105 sub operation_bucket_acl_get {
106 4 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_acl_get: called CC=1 SCAR=0.0
Pod undocumented
107  
108 $self
109 ->bucket ($params{with_bucket})
110 4 ->get_acl
111 ;
112 }
113  
114 sub operation_bucket_acl_set {
115 9 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_acl_set: called CC=1 SCAR=0.0
Pod undocumented
116  
117 $self
118 ->bucket ($params{with_bucket})
119 ->set_acl ({
120 (acl => $params{with_acl}) x!! exists $params{with_acl},
121 (acl_short => $params{with_acl_short}) x!! exists $params{with_acl_short},
122 (acl_xml => $params{with_acl_xml}) x!! exists $params{with_acl_xml},
123 })
124 9 ;
125 }
126  
127 sub operation_bucket_create {
128 15 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_create: called CC=1 SCAR=0.0
Pod undocumented
129  
130 $self
131 ->add_bucket ({
132 bucket => $params{with_bucket},
133 (acl => $params{with_acl}) x!! exists $params{with_acl},
134 (acl_short => $params{with_acl_short}) x!! exists $params{with_acl_short},
135 (location_constraint => $params{with_region}) x!! exists $params{with_region},
136 (region => $params{with_region}) x!! exists $params{with_region},
137 })
138 15 ;
139 }
140  
141 sub operation_bucket_delete {
142 5 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_delete: called CC=1 SCAR=0.0
Pod undocumented
143  
144 $self
145 ->delete_bucket ({
146 bucket => $params{with_bucket},
147 })
148 5 ;
149 }
150  
151 sub operation_bucket_objects_list {
152 8 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_objects_list: called CC=1 SCAR=0.0
Pod undocumented
153  
154 $self
155 ->list_bucket ({
156 bucket => $params{with_bucket},
157 delimiter => $params{with_delimiter},
158 max_keys => $params{with_max_keys},
159 marker => $params{with_marker},
160 prefix => $params{with_prefix},
161 })
162 8 ;
163 }
164  
165 sub operation_bucket_objects_delete {
166 4 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_objects_delete: called CC=1 SCAR=0.0
Pod undocumented
167  
168 $self
169 ->bucket ($params{with_bucket})
170 4 ->delete_multi_object (@{ $params{with_keys} })
171 ;
172 }
173  
174 sub operation_object_acl_get {
175 5 ▶ my ($self, %params) = @_;
Subroutine operation_object_acl_get: called CC=1 SCAR=0.0
Pod undocumented
176  
177 $self
178 ->bucket ($params{with_bucket})
179 ->get_acl ($params{with_key})
180 5 ;
181 }
182  
183 sub operation_object_acl_set {
184 9 ▶ my ($self, %params) = @_;
Subroutine operation_object_acl_set: called CC=1 SCAR=0.0
Pod undocumented
185  
186 $self
187 ->bucket ($params{with_bucket})
188 ->set_acl ({
189 key => $params{with_key},
190 (acl => $params{with_acl}) x!! exists $params{with_acl},
191 (acl_short => $params{with_acl_short}) x!! exists $params{with_acl_short},
192 (acl_xml => $params{with_acl_xml}) x!! exists $params{with_acl_xml},
193 })
194 9 ;
195 }
196  
197 sub operation_object_create {
198 10 ▶ my ($self, %params) = @_;
Subroutine operation_object_create: called CC=6 SCAR=17.9
Pod undocumented
199  
200 10 ▶ my $headers = { %{ $params{with_headers} || {} } };
Branch: 1 branch
BranchTrueFalseTotal
$params{"with_headers"} or {} 10 0 10
201  
202 $headers->{$_} = $params{"with_$_"}
203 10 for grep exists $params{"with_$_"},
204 qw[ cache_control ],
205 qw[ content_disposition ],
206 qw[ content_encoding ],
207 qw[ content_type ],
208 qw[ encryption ],
209 qw[ expires ],
210 qw[ acl_short ],
211 qw[ acl ],
212 ;
213  
214 $headers->{x_amz_storage_class} = $params{with_storage_class}
215 10 ▶ if $params{with_storage_class};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"with_storage_class"} 1 9 10
216  
217 $headers->{"x_amz_meta_\L$_"} = $params{with_user_metadata}{$_}
218 10 ▶ for keys %{ $params{with_user_metadata} || {} };
Branch: 1 branch
BranchTrueFalseTotal
$params{"with_user_metadata"} or {} 9 1 10
219  
220 $self
221 ->bucket ($params{with_bucket})
222 ->add_key (
223 $params{with_key},
224 $params{with_value},
225 10 $headers,
226 )
227 ;
228 }
229  
230 sub operation_object_delete {
231 5 ▶ my ($self, %params) = @_;
Subroutine operation_object_delete: called CC=1 SCAR=0.0
Pod undocumented
232  
233 $self
234 ->bucket ($params{with_bucket})
235 ->delete_key ($params{with_key})
236 5 ;
237 }
238  
239 sub operation_object_fetch {
240 7 ▶ my ($self, %params) = @_;
Subroutine operation_object_fetch: called CC=1 SCAR=0.0
Pod undocumented
241  
242 $self
243 ->bucket ($params{with_bucket})
244 ->get_key (
245 $params{with_key},
246 'GET',
247 ({ range => $params{with_range} }) x exists $params{with_range},
248 )
249 7 ;
250 }
251  
252 sub operation_object_head {
253 5 ▶ my ($self, %params) = @_;
Subroutine operation_object_head: called CC=1 SCAR=0.0
Pod undocumented
254  
255 $self
256 ->bucket ($params{with_bucket})
257 ->head_key ($params{with_key})
258 5 ;
259 }
260  
261 sub operation_bucket_tags_add {
262 4 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_tags_add: called CC=1 SCAR=0.0
Pod undocumented
263  
264 $self
265 ->bucket ($params{with_bucket})
266 ->add_tags ({
267 tags => $params{with_tags},
268 })
269 4 ;
270 }
271  
272 sub operation_object_tags_add {
273 4 ▶ my ($self, %params) = @_;
Subroutine operation_object_tags_add: called CC=1 SCAR=0.0
Pod undocumented
274  
275 $self
276 ->bucket ($params{with_bucket})
277 ->add_tags ({
278 key => $params{with_key},
279 tags => $params{with_tags},
280 (version_id => $params{with_version_id}) x!! defined $params{with_version_id},
281 })
282 4 ;
283 }
284  
285 sub operation_bucket_tags_delete {
286 4 ▶ my ($self, %params) = @_;
Subroutine operation_bucket_tags_delete: called CC=1 SCAR=0.0
Pod undocumented
287  
288 $self
289 ->bucket ($params{with_bucket})
290 4 ->delete_tags
291 ;
292 }
293  
294 sub operation_object_tags_delete {
295 5 ▶ my ($self, %params) = @_;
Subroutine operation_object_tags_delete: called CC=1 SCAR=0.0
Pod undocumented
296  
297 $self
298 ->bucket ($params{with_bucket})
299 ->delete_tags ({
300 key => $params{with_key},
301 (version_id => $params{with_version_id}) x!! defined $params{with_version_id},
302 })
303 5 ;
304 }
305  
306 90 1;
307  
308 __END__
309  
310 =pod
311  
312 =encoding UTF-8
313  
314 =head1 NAME
315  
316 Shared::Examples::Net::Amazon::S3::API - used for testing and as example
317  
318 =head1 VERSION
319  
320 version 0.99
321  
322 =head1 AUTHOR
323  
324 Branislav Zahradník <barney@cpan.org>
325  
326 =head1 COPYRIGHT AND LICENSE
327  
328 This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.
329  
330 This is free software; you can redistribute it and/or modify it under
331 the same terms as the Perl 5 programming language system itself.
332  
333 =cut
« Shared/Examples/Net/Amazon/S3/Client.pm ↑ Summary Net/Amazon/S3/Request/Role/XML/Content.pm »