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

filter: Statementstmt 98.9% 92 / 93 Branchbran 66.6% 4 / 6 Conditioncond 71.4% 5 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 34 / 34 Podpod 0.0% 0 / 17 totaltotal 84.4% 136 / 161 CC 7 SCAR 3.2
CC
7
Cov
95%
operation_object_create
3.5
_default_with_api
2.0
operation_object_head
2.0
CRAP 1.4
« Net/Amazon/S3/Request/Role/HTTP/Header/ACL.pm ↑ Summary Net/Amazon/S3/Operation/Object/Upload/Part/Request.pm »
1 package Shared::Examples::Net::Amazon::S3::Client;
2 # ABSTRACT: used for testing and as example
3 90 $Shared::Examples::Net::Amazon::S3::Client::VERSION = '0.992';
4 193 ▶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 HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 90 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 90 ▶use Sub::Override;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 90 ▶use Test::Deep;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 90 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 90 ▶use Net::Amazon::S3::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 90 ▶use Shared::Examples::Net::Amazon::S3;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 90 our @EXPORT_OK = (
20 qw[ expect_signed_uri ],
21 qw[ expect_client_list_all_my_buckets ],
22 qw[ expect_client_bucket_acl_get ],
23 qw[ expect_client_bucket_acl_set ],
24 qw[ expect_client_bucket_create ],
25 qw[ expect_client_bucket_delete ],
26 qw[ expect_client_bucket_objects_delete ],
27 qw[ expect_client_bucket_objects_list ],
28 qw[ expect_client_bucket_tags_add ],
29 qw[ expect_client_bucket_tags_delete ],
30 qw[ expect_client_object_acl_set ],
31 qw[ expect_client_object_create ],
32 qw[ expect_client_object_delete ],
33 qw[ expect_client_object_fetch ],
34 qw[ expect_client_object_head ],
35 qw[ expect_client_object_tags_add],
36 qw[ expect_client_object_tags_delete],
37 );
38  
39 90 *with_fixture = *Shared::Examples::Net::Amazon::S3::with_fixture;
40  
41 90 ▶sub _exporter_expand_sub {
Subroutine _exporter_expand_sub: called CC=1 SCAR=0.0
42 90 my ($self, $name, $args, $globals) = @_;
43  
44 90 my $s3_operation = $name;
45 90 $s3_operation =~ s/_client_/_operation_/;
46  
47 90 ▶ return +( $name => eval <<"GEN_SUB" );
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
48 sub {
49 push \@_, -shared_examples => __PACKAGE__;
50 goto \\& Shared::Examples::Net::Amazon::S3::$s3_operation;
51 }
52 GEN_SUB
53 }
54  
55 144 ▶sub _default_with_api {
Subroutine _default_with_api: called CC=2 SCAR=7.1
56 144 my ($self, $params) = @_;
57  
58 144 ▶ $params->{with_client} ||= Net::Amazon::S3::Client->new (
Condition66%2/3
$params->{"with_client"} ||= "Net::Amazon::S3::Client"->new("s3", Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2())
l!l&&r!l&&!r
41400
MC/DC0%0/2
$params->{"with_client"} ||= "Net::Amazon::S3::Client"->new("s3", Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2())
$params->{"with_client"} "Net::Amazon::S3::Client"->new("s3", Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2())
Truth table66%2/3
A ||= B
A= $params->{"with_client"}B= "Net::Amazon::S3::Client"->new("s3", Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2())
ABresult
1X1
011
000
59 s3 => Shared::Examples::Net::Amazon::S3::s3_api_with_signature_2 ()
60 );
61 }
62  
63 103 ▶sub _mock_http_response {
Subroutine _mock_http_response: called CC=1 SCAR=0.0
64 103 my ($self, $api, %params) = @_;
65  
66 103 Shared::Examples::Net::Amazon::S3->s3_api_mock_http_response (
67 $api->s3,
68 %params,
69 )
70 }
71  
72 4 ▶sub expect_signed_uri {
Subroutine expect_signed_uri: called CC=2 SCAR=6.9
Pod undocumented
73 4 my ($title, %params) = @_;
74  
75 4 Hash::Util::lock_keys %params,
76 qw[ with_client ],
77 qw[ with_bucket ],
78 qw[ with_region ],
79 qw[ with_key ],
80 qw[ with_expire_at ],
81 qw[ with_method ],
82 qw[ expect_uri ],
83 ;
84  
85 my $guard = Sub::Override->new (
86 3 ▶ 'Net::Amazon::S3::Bucket::region' => sub { $params{with_region } },
Subroutine __ANON__: called CC=1 SCAR=0.0
87 4 );
88  
89 my $got = $params{with_client}
90 ->bucket (
91 name => $params{with_bucket},
92 )
93 ->object (
94 key => $params{with_key},
95 expires => $params{with_expire_at},
96 )
97 ->query_string_authentication_uri_for_method (
98 4 ▶ $params{with_method} || 'GET',
Condition100%2/2
$params{'with_method'} || 'GET'
l!l
13
MC/DC100%1/1
$params{'with_method'} || 'GET'
$params{'with_method'}
Truth table100%2/2
A
A= $params{'with_method'}
Aresult
11
00
99 )
100 ;
101  
102 4 cmp_deeply $got, $params{expect_uri}, $title;
103 }
104  
105 4 ▶sub operation_list_all_my_buckets {
Subroutine operation_list_all_my_buckets: called CC=1 SCAR=0.0
Pod undocumented
106 4 my ($self, %params) = @_;
107  
108 4 [ $_[0]->buckets ];
109 }
110  
111 4 ▶sub operation_bucket_acl_get {
Subroutine operation_bucket_acl_get: called CC=1 SCAR=0.0
Pod undocumented
112 4 my ($self, %params) = @_;
113  
114 $self
115 ->bucket (name => $params{with_bucket})
116 4 ->acl
117 ;
118 }
119  
120 14 ▶sub operation_bucket_create {
Subroutine operation_bucket_create: called CC=1 SCAR=0.0
Pod undocumented
121 14 my ($self, %params) = @_;
122  
123 $self->create_bucket(
124 name => $params{with_bucket},
125 (acl => $params{with_acl}) x!! exists $params{with_acl},
126 (acl_short => $params{with_acl_short}) x!! exists $params{with_acl_short},
127 (location_constraint => $params{with_region}) x!! exists $params{with_region},
128 14 );
129 }
130  
131 5 ▶sub operation_bucket_delete {
Subroutine operation_bucket_delete: called CC=1 SCAR=0.0
Pod undocumented
132 5 my ($self, %params) = @_;
133  
134 $self
135 ->bucket (name => $params{with_bucket})
136 5 ->delete
137 ;
138 }
139  
140 7 ▶sub operation_bucket_objects_list {
Subroutine operation_bucket_objects_list: called CC=1 SCAR=0.0
Pod undocumented
141 7 my ($self, %params) = @_;
142  
143 $self
144 ->bucket (name => $params{with_bucket})
145 ->list ({
146 bucket => $params{with_bucket},
147 delimiter => $params{with_delimiter},
148 max_keys => $params{with_max_keys},
149 marker => $params{with_marker},
150 prefix => $params{with_prefix},
151 })
152 7 ;
153 }
154  
155 4 ▶sub operation_bucket_objects_delete {
Subroutine operation_bucket_objects_delete: called CC=1 SCAR=0.0
Pod undocumented
156 4 my ($self, %params) = @_;
157  
158 $self
159 ->bucket (name => $params{with_bucket})
160 4 ->delete_multi_object (@{ $params{with_keys} })
161 ;
162 }
163  
164 10 ▶sub operation_object_create {
Subroutine operation_object_create: called CC=3 SCAR=12.5
Pod undocumented
165 10 my ($self, %params) = @_;
166  
167 $self
168 ->bucket (name => $params{with_bucket})
169 ->object (
170 key => $params{with_key},
171 map +($_ => $params{"with_$_"}),
172 grep exists $params{"with_$_"}, (
173 qw[ cache_control ],
174 qw[ content_disposition ],
175 qw[ content_encoding ],
176 qw[ content_type ],
177 qw[ encryption ],
178 qw[ expires ],
179 qw[ storage_class ],
180 qw[ user_metadata ],
181 qw[ acl ],
182 qw[ acl_short ],
183 )
184 )
185 10 ▶ ->${\ (ref $params{with_value} ? 'put_filename' : 'put' ) } (
Branch: 1 branch
BranchTrueFalseTotal
ref $params{'with_value'} ? : 0 10 10
186 0 ref $params{with_value} ? ${ $params{with_value} } : $params{with_value}
187 )
188 10 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
ref $params{'with_value'} ? : 0 10 10
189 }
190  
191 5 ▶sub operation_object_delete {
Subroutine operation_object_delete: called CC=1 SCAR=0.0
Pod undocumented
192 5 my ($self, %params) = @_;
193  
194 $self
195 ->bucket (name => $params{with_bucket})
196 ->object (key => $params{with_key})
197 5 ->delete
198 ;
199 }
200  
201 6 ▶sub operation_object_fetch {
Subroutine operation_object_fetch: called CC=2 SCAR=6.9
Pod undocumented
202 6 my ($self, %params) = @_;
203  
204 my $object = $self
205 ->bucket (name => $params{with_bucket})
206 ->object (key => $params{with_key})
207 6 ;
208  
209 $object = $object->range ($params{with_range})
210 6 ▶ if $params{with_range};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"with_range"} 1 5 6
211  
212 6 $object->get;
213 }
214  
215 10 ▶sub operation_object_head {
Subroutine operation_object_head: called CC=2 SCAR=7.1
Pod undocumented
216 10 my ($self, %params) = @_;
217  
218 10 ▶ my $method = $params{-method} // 'exists';
Condition50%1/2
$params{"-method"} // "exists"
l!l
100
MC/DC0%0/1
$params{"-method"} // "exists"
$params{"-method"}
Truth table50%1/2
A
A= $params{"-method"}
Aresult
11
00
219  
220 $self
221 ->bucket (name => $params{with_bucket})
222 ->object (key => $params{with_key})
223 10 ->$method
224 ;
225 }
226  
227 8 ▶sub operation_bucket_acl_set {
Subroutine operation_bucket_acl_set: called CC=1 SCAR=0.0
Pod undocumented
228 8 my ($self, %params) = @_;
229  
230 $self
231 ->bucket (name => $params{with_bucket})
232 ->set_acl (
233 (acl => $params{with_acl}) x!! exists $params{with_acl},
234 (acl_short => $params{with_acl_short}) x!! exists $params{with_acl_short},
235 (acl_xml => $params{with_acl_xml}) x!! exists $params{with_acl_xml},
236 )
237 8 ;
238 }
239  
240 9 ▶sub operation_object_acl_set {
Subroutine operation_object_acl_set: called CC=1 SCAR=0.0
Pod undocumented
241 9 my ($self, %params) = @_;
242  
243 $self
244 ->bucket (name => $params{with_bucket})
245 ->object (key => $params{with_key})
246 ->set_acl (
247 (acl => $params{with_acl}) x!! exists $params{with_acl},
248 (acl_short => $params{with_acl_short}) x!! exists $params{with_acl_short},
249 (acl_xml => $params{with_acl_xml}) x!! exists $params{with_acl_xml},
250 )
251 9 ;
252 }
253  
254 4 ▶sub operation_bucket_tags_add {
Subroutine operation_bucket_tags_add: called CC=1 SCAR=0.0
Pod undocumented
255 4 my ($self, %params) = @_;
256  
257 $self
258 ->bucket (name => $params{with_bucket})
259 ->add_tags (
260 tags => $params{with_tags},
261 )
262 4 ;
263 }
264  
265 4 ▶sub operation_object_tags_add {
Subroutine operation_object_tags_add: called CC=1 SCAR=0.0
Pod undocumented
266 4 my ($self, %params) = @_;
267  
268 $self
269 ->bucket (name => $params{with_bucket})
270 ->object (key => $params{with_key})
271 ->add_tags (
272 tags => $params{with_tags},
273 (version_id => $params{with_version_id}) x!! defined $params{with_version_id},
274 )
275 4 ;
276 }
277  
278 4 ▶sub operation_bucket_tags_delete {
Subroutine operation_bucket_tags_delete: called CC=1 SCAR=0.0
Pod undocumented
279 4 my ($self, %params) = @_;
280  
281 $self
282 ->bucket (name => $params{with_bucket})
283 4 ->delete_tags
284 ;
285 }
286  
287 5 ▶sub operation_object_tags_delete {
Subroutine operation_object_tags_delete: called CC=1 SCAR=0.0
Pod undocumented
288 5 my ($self, %params) = @_;
289  
290 $self
291 ->bucket (name => $params{with_bucket})
292 ->object (key => $params{with_key})
293 ->delete_tags (
294 (version_id => $params{with_version_id}) x!! defined $params{with_version_id},
295 )
296 5 ;
297 }
298  
299 90 1;
300  
301 __END__
« Net/Amazon/S3/Request/Role/HTTP/Header/ACL.pm ↑ Summary Net/Amazon/S3/Operation/Object/Upload/Part/Request.pm »