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

filter: Statementstmt 100% 84 / 84 Branchbran 100% 2 / 2 Conditioncond 71.4% 5 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 30 / 30 Podpod 0.0% 0 / 18 totaltotal 84.1% 122 / 145 CC 7 SCAR 6.4
CC
7
Cov
98%
operation_object_create
6.0
_default_with_api
2.0
BEGIN
1.0
CRAP 1.9
« Net/Amazon/S3/X.pm ↑ Summary Net/Amazon/S3/Error/Handler/Status.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.992';
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 20 ▶sub _exporter_expand_sub {
Subroutine _exporter_expand_sub: called CC=1 SCAR=0.0
41 20 my ($self, $name, $args, $globals) = @_;
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 187 ▶sub _default_with_api {
Subroutine _default_with_api: called CC=2 SCAR=7.1
55 187 my ($self, $params) = @_;
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 107 ▶sub _mock_http_response {
Subroutine _mock_http_response: called CC=1 SCAR=0.0
61 107 my (undef, $api, %params) = @_;
62  
63 107 Shared::Examples::Net::Amazon::S3->s3_api_mock_http_response (
64 $api,
65 %params,
66 )
67 }
68  
69 4 ▶sub expect_signed_uri {
Subroutine expect_signed_uri: called CC=1 SCAR=0.0
Pod undocumented
70 4 my ($title, %params) = @_;
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 4 ▶sub operation_list_all_my_buckets {
Subroutine operation_list_all_my_buckets: called CC=1 SCAR=0.0
Pod undocumented
100 4 my ($self, %params) = @_;
101  
102 4 $self->buckets;
103 }
104  
105 4 ▶sub operation_bucket_acl_get {
Subroutine operation_bucket_acl_get: called CC=1 SCAR=0.0
Pod undocumented
106 4 my ($self, %params) = @_;
107  
108 $self
109 ->bucket ($params{with_bucket})
110 4 ->get_acl
111 ;
112 }
113  
114 9 ▶sub operation_bucket_acl_set {
Subroutine operation_bucket_acl_set: called CC=1 SCAR=0.0
Pod undocumented
115 9 my ($self, %params) = @_;
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 15 ▶sub operation_bucket_create {
Subroutine operation_bucket_create: called CC=1 SCAR=0.0
Pod undocumented
128 15 my ($self, %params) = @_;
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 5 ▶sub operation_bucket_delete {
Subroutine operation_bucket_delete: called CC=1 SCAR=0.0
Pod undocumented
142 5 my ($self, %params) = @_;
143  
144 $self
145 ->delete_bucket ({
146 bucket => $params{with_bucket},
147 })
148 5 ;
149 }
150  
151 8 ▶sub operation_bucket_objects_list {
Subroutine operation_bucket_objects_list: called CC=1 SCAR=0.0
Pod undocumented
152 8 my ($self, %params) = @_;
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 4 ▶sub operation_bucket_objects_delete {
Subroutine operation_bucket_objects_delete: called CC=1 SCAR=0.0
Pod undocumented
166 4 my ($self, %params) = @_;
167  
168 $self
169 ->bucket ($params{with_bucket})
170 4 ->delete_multi_object (@{ $params{with_keys} })
171 ;
172 }
173  
174 5 ▶sub operation_object_acl_get {
Subroutine operation_object_acl_get: called CC=1 SCAR=0.0
Pod undocumented
175 5 my ($self, %params) = @_;
176  
177 $self
178 ->bucket ($params{with_bucket})
179 ->get_acl ($params{with_key})
180 5 ;
181 }
182  
183 9 ▶sub operation_object_acl_set {
Subroutine operation_object_acl_set: called CC=1 SCAR=0.0
Pod undocumented
184 9 my ($self, %params) = @_;
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 10 ▶sub operation_object_create {
Subroutine operation_object_create: called CC=6 SCAR=17.9
Pod undocumented
198 10 my ($self, %params) = @_;
199  
200 10 ▶ my $headers = { %{ $params{with_headers} || {} } };
Condition50%1/2
$params{'with_headers'} || {}
l!l
010
MC/DC0%0/1
$params{'with_headers'} || {}
$params{'with_headers'}
Truth table50%1/2
A
A= $params{'with_headers'}
Aresult
11
00
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} || {} };
Condition100%2/2
$params{'with_user_metadata'} || {}
l!l
19
MC/DC100%1/1
$params{'with_user_metadata'} || {}
$params{'with_user_metadata'}
Truth table100%2/2
A
A= $params{'with_user_metadata'}
Aresult
11
00
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 5 ▶sub operation_object_delete {
Subroutine operation_object_delete: called CC=1 SCAR=0.0
Pod undocumented
231 5 my ($self, %params) = @_;
232  
233 $self
234 ->bucket ($params{with_bucket})
235 ->delete_key ($params{with_key})
236 5 ;
237 }
238  
239 7 ▶sub operation_object_fetch {
Subroutine operation_object_fetch: called CC=1 SCAR=0.0
Pod undocumented
240 7 my ($self, %params) = @_;
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 5 ▶sub operation_object_head {
Subroutine operation_object_head: called CC=1 SCAR=0.0
Pod undocumented
253 5 my ($self, %params) = @_;
254  
255 $self
256 ->bucket ($params{with_bucket})
257 ->head_key ($params{with_key})
258 5 ;
259 }
260  
261 4 ▶sub operation_bucket_tags_add {
Subroutine operation_bucket_tags_add: called CC=1 SCAR=0.0
Pod undocumented
262 4 my ($self, %params) = @_;
263  
264 $self
265 ->bucket ($params{with_bucket})
266 ->add_tags ({
267 tags => $params{with_tags},
268 })
269 4 ;
270 }
271  
272 4 ▶sub operation_object_tags_add {
Subroutine operation_object_tags_add: called CC=1 SCAR=0.0
Pod undocumented
273 4 my ($self, %params) = @_;
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 4 ▶sub operation_bucket_tags_delete {
Subroutine operation_bucket_tags_delete: called CC=1 SCAR=0.0
Pod undocumented
286 4 my ($self, %params) = @_;
287  
288 $self
289 ->bucket ($params{with_bucket})
290 4 ->delete_tags
291 ;
292 }
293  
294 5 ▶sub operation_object_tags_delete {
Subroutine operation_object_tags_delete: called CC=1 SCAR=0.0
Pod undocumented
295 5 my ($self, %params) = @_;
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__
« Net/Amazon/S3/X.pm ↑ Summary Net/Amazon/S3/Error/Handler/Status.pm »