StorageClient/Blob.pm

filter: Statementstmt 5.3% 42 / 783 Branchbran 0.0% 0 / 396 Conditioncond 0.0% 0 / 98 MC/DCmcdc 0.0% 0 / 60 Subroutinesub 20.0% 13 / 65 Podpod 75.0% 33 / 44 totaltotal 6.0% 88 / 1446 CC 252 SCAR 65.0
CC
252
Cov
3%
download
1980.0
upload
1892.0
_get
552.0
CRAP 661.8
↑ Summary StorageClient.pm »
1 #!perl
2 # ABSTRACT: Object representing a blob in Azure Blob Storage
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package Net::Azure::StorageClient::Blob;
9 2 $Net::Azure::StorageClient::Blob::VERSION = '0.6';
10 2 ▶use parent qw/Net::Azure::StorageClient/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use HTTP::Date qw/ str2time /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use File::Path qw/ mkpath /;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use File::Find qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
23 0 my ( $self, %args ) = @_;
24 0 $self->SUPER::init( %args );
25 0 my $container_name = $args{ container_name };
26 0 ▶ if ( $container_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($container_name) 0 0 0
27 0 $container_name =~ s!/!!g;
28 0 $self->{ container_name } = $container_name;
29 }
30 0 $self->{ type } = 'blob';
31 0 return $self;
32 }
33  
34 0 ▶sub list_containers {
Subroutine list_containers: not called CC=1 SCAR=6.9
Pod documented
35 0 my ( $self, $params ) = @_;
36 0 return $self->list( '', $params );
37 }
38  
39 { # scope $xml
40  
41 2 my $xml = XML::Simple->new;
42  
43 0 ▶sub set_blob_service_properties {
Subroutine set_blob_service_properties: not called CC=15 SCAR=54.8
Pod documented
44 0 my ( $self, $params ) = @_;
45 0 my $prop = $self->get_blob_service_properties( $params );
46 0 ▶ if ( $prop->code != 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop->code != 200) 0 0 0
47 0 return $prop;
48 }
49 0 my $result = $prop->content;
50 0 my $list = $xml->XMLin( $result );
51 0 my $properties = $params->{ StorageServicePropertie };
52 0 my @properties_Logging = qw/ Version Delete Write Read /;
53 0 my @properties_Metrics = qw/ Version Enabled IncludeAPIs /;
54 0 for my $prop( @properties_Logging ) {
55 $properties->{ Logging }->{ $prop } = $list->{ Logging }->{ $prop }
56 if ( (! $properties->{ Logging }->{ $prop } )
57 0 ▶ && ( $list->{ Logging }->{ $prop } ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $properties->{"Logging"}{$prop} and $list->{"Logging"}{$prop} 0 0 0
Condition0%0/3
not $properties->{"Logging"}{$prop} and $list->{"Logging"}{$prop}
!ll&&!rl&&r
000
MC/DC0%0/2
not $properties->{"Logging"}{$prop} and $list->{"Logging"}{$prop}
not $properties->{"Logging"}{$prop} $list->{"Logging"}{$prop}
Truth table0%0/3
not(A) and B
A= not $properties->{"Logging"}{$prop}B= $list->{"Logging"}{$prop}
ABresult
0X0
100
111
58 }
59 $properties->{ Logging }->{ 'RetentionPolicy' } = $list->{ Logging }->{ RetentionPolicy }
60 0 ▶ unless $properties->{ Logging }->{ RetentionPolicy } && $list->{ Logging }->{ RetentionPolicy };
Branch: 1 branch
BranchTrueFalseTotal
unless $properties->{"Logging"}{"RetentionPolicy"} and $list->{"Logging"}{"RetentionPolicy"} 0 0 0
Condition0%0/3
$properties->{"Logging"}{"RetentionPolicy"} and $list->{"Logging"}{"RetentionPolicy"}
!ll&&!rl&&r
000
MC/DC0%0/2
$properties->{"Logging"}{"RetentionPolicy"} and $list->{"Logging"}{"RetentionPolicy"}
$properties->{"Logging"}{"RetentionPolicy"} $list->{"Logging"}{"RetentionPolicy"}
Truth table0%0/3
A and B
A= $properties->{"Logging"}{"RetentionPolicy"}B= $list->{"Logging"}{"RetentionPolicy"}
ABresult
0X0
100
111
61 0 for my $prop( @properties_Metrics ) {
62 $properties->{ Metrics }->{ $prop } = $list->{ Metrics }->{ $prop }
63 if ( (! $properties->{ Metrics }->{ $prop } )
64 0 ▶ && ( $list->{ Metrics }->{ $prop } ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $properties->{"Metrics"}{$prop} and $list->{"Metrics"}{$prop} 0 0 0
Condition0%0/3
not $properties->{"Metrics"}{$prop} and $list->{"Metrics"}{$prop}
!ll&&!rl&&r
000
MC/DC0%0/2
not $properties->{"Metrics"}{$prop} and $list->{"Metrics"}{$prop}
not $properties->{"Metrics"}{$prop} $list->{"Metrics"}{$prop}
Truth table0%0/3
not(A) and B
A= not $properties->{"Metrics"}{$prop}B= $list->{"Metrics"}{$prop}
ABresult
0X0
100
111
65 }
66 $properties->{ Metrics }->{ 'RetentionPolicy' } = $list->{ Metrics }->{ RetentionPolicy }
67 0 ▶ unless $properties->{ Metrics }->{ RetentionPolicy } && $list->{ Metrics }->{ RetentionPolicy };
Branch: 1 branch
BranchTrueFalseTotal
unless $properties->{"Metrics"}{"RetentionPolicy"} and $list->{"Metrics"}{"RetentionPolicy"} 0 0 0
Condition0%0/3
$properties->{"Metrics"}{"RetentionPolicy"} and $list->{"Metrics"}{"RetentionPolicy"}
!ll&&!rl&&r
000
MC/DC0%0/2
$properties->{"Metrics"}{"RetentionPolicy"} and $list->{"Metrics"}{"RetentionPolicy"}
$properties->{"Metrics"}{"RetentionPolicy"} $list->{"Metrics"}{"RetentionPolicy"}
Truth table0%0/3
A and B
A= $properties->{"Metrics"}{"RetentionPolicy"}B= $list->{"Metrics"}{"RetentionPolicy"}
ABresult
0X0
100
111
68 0 ▶ if (! $properties->{ DefaultServiceVersion } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($properties->{"DefaultServiceVersion"}) 0 0 0
69 $properties->{ DefaultServiceVersion } = $list->{ DefaultServiceVersion }
70 0 ▶ if $list->{ DefaultServiceVersion };
Branch: 1 branch
BranchTrueFalseTotal
if $list->{"DefaultServiceVersion"} 0 0 0
71 }
72 0 my $body = $xml->XMLout( $properties, NoAttr => 1, RootName => 'StorageServiceProperties' );
73 0 $body = '<?xml version="1.0" encoding="utf-8"?>' . "\n${body}";
74 0 my $data = '?restype=service&comp=properties';
75 0 my $options = $params->{ options };
76 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
77 0 $params->{ body } = $body;
78 0 return $self->put( $data, $params );
79 }
80  
81 } # scope $xml
82  
83 2 ▶sub get_blob_service_properties {
Subroutine get_blob_service_properties: not called CC=2 SCAR=15.4
Pod documented
84 0 my ( $self, $params ) = @_;
85 0 my $data = '?restype=service&comp=properties';
86 0 my $options = $params->{ options };
87 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
88 0 return $self->get( $data, $params );
89 }
90  
91 0 ▶sub create_container {
Subroutine create_container: not called CC=4 SCAR=30.0
Pod documented
92 0 my ( $self, $name, $params ) = @_;
93 0 $name =~ s!^/!!;
94 0 my $data = 'restype=container';
95 0 my $options = $params->{ options };
96 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
97 0 my $path = "${name}?${data}";
98 0 ▶ if ( my $public_access = $params->{ public_access } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $public_access = $params->{"public_access"}) 0 0 0
99 0 ▶ if ( $public_access !~ m/^blob|container$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($public_access =~ /^blob|container$/) 0 0 0
100 0 $public_access = 'container';
101 }
102 0 $params->{ headers }->{ 'x-ms-blob-public-access' } = $public_access;
103 }
104 0 $params->{ body } = $data;
105 0 return $self->put( $path, $params );
106 }
107  
108 0 ▶sub get_container_properties {
Subroutine get_container_properties: not called CC=1 SCAR=6.9
Pod documented
109 0 my $self = shift;
110 0 return $self->get_properties( @_ );
111 }
112  
113 0 ▶sub get_container_metadata {
Subroutine get_container_metadata: not called CC=1 SCAR=6.9
Pod documented
114 0 my $self = shift;
115 0 return $self->get_metadata( @_ );
116 }
117  
118 0 ▶sub set_container_metadata {
Subroutine set_container_metadata: not called CC=1 SCAR=6.9
Pod documented
119 0 my $self = shift;
120 0 return $self->set_metadata( @_ );
121 }
122  
123 0 ▶sub get_container_acl {
Subroutine get_container_acl: not called CC=2 SCAR=17.9
Pod documented
124 0 my ( $self, $name, $params ) = @_;
125 0 $name =~ s!^/!!;
126 0 $name .= '?restype=container&comp=acl';
127 0 my $options = $params->{ options };
128 0 ▶ $name .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
129 0 return $self->get( $name, $params );
130 }
131  
132 0 ▶sub set_container_acl {
Subroutine set_container_acl: not called CC=5 SCAR=34.0
Pod documented
133 0 my ( $self, $name, $params ) = @_;
134 0 $name =~ s!^/!!;
135 0 $name .= '?restype=container&comp=acl';
136 0 my $options = $params->{ options };
137 0 ▶ $name .= '&' . $options if $options; # timeout=n
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
138 0 ▶ if ( my $public_access = $params->{ public_access } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $public_access = $params->{"public_access"}) 0 0 0
139 0 ▶ if ( $public_access !~ m/^blob|container$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($public_access =~ /^blob|container$/) 0 0 0
140 0 $public_access = 'container';
141 }
142 0 $params->{ headers }->{ 'x-ms-blob-public-access' } = $public_access;
143 }
144 0 ▶ my $Permission = $params->{ Permission } || 'rwdl';
Condition0%0/2
$params->{'Permission'} || 'rwdl'
l!l
00
MC/DC0%0/1
$params->{'Permission'} || 'rwdl'
$params->{'Permission'}
Truth table0%0/2
A
A= $params->{'Permission'}
Aresult
11
00
145 0 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, undef ) = localtime( time );
146 0 my $ts = sprintf( '%04d-%02d-%02d', $year + 1900, $mon + 1, $mday );
147 0 my $id = $self->_signed_identifier( 64 );
148 0 my $SignedIdentifiers = { SignedIdentifier => { Id => $id,
149 AccessPolicy => { Start => $ts,
150 Expiry => $ts,
151 Permission => $Permission }, }, };
152 0 my $xml = XML::Simple->new;
153 0 my $body = $xml->XMLout( $SignedIdentifiers, NoAttr => 1, RootName => 'SignedIdentifiers' );
154 0 $body = '<?xml version="1.0" encoding="utf-8"?>' . "\n${body}";
155 0 $params->{ body } = $body;
156 0 return $self->put( $name, $params );
157 }
158  
159 0 ▶sub delete_container {
Subroutine delete_container: not called CC=2 SCAR=17.9
Pod documented
160 0 my ( $self, $name, $params ) = @_;
161 0 $name =~ s!^/!!;
162 0 my $data = 'restype=container';
163 0 my $options = $params->{ options };
164 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
165 0 my $path = "${name}?${data}";
166 0 return $self->delete( $path, $params );
167 }
168  
169 0 ▶sub lease_container {
Subroutine lease_container: not called CC=1 SCAR=6.9
Pod documented
170 0 my $self = shift;
171 0 return $self->lease( @_ );
172 }
173  
174 0 ▶sub list_blobs {
Subroutine list_blobs: not called CC=2 SCAR=17.9
Pod documented
175 0 my $self = shift;
176 0 ▶ if ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 0 0
177 0 my @blobs = $self->list( @_ );
178 0 return @blobs;
179 }
180 0 my $blobs = $self->list( @_ );
181 0 return $blobs;
182 }
183  
184 0 ▶sub put_blob {
Subroutine put_blob: not called CC=1 SCAR=6.9
Pod documented
185 0 my $self = shift;
186 0 return $self->_put( @_ );
187 }
188  
189 0 ▶sub get_blob {
Subroutine get_blob: not called CC=1 SCAR=6.9
Pod documented
190 0 my $self = shift;
191 0 return $self->_get( @_ );
192 }
193  
194 0 ▶sub get_blob_properties {
Subroutine get_blob_properties: not called CC=1 SCAR=6.9
Pod documented
195 0 my $self = shift;
196 0 return $self->get_properties( @_ );
197 }
198  
199 0 ▶sub set_blob_properties {
Subroutine set_blob_properties: not called CC=1 SCAR=6.9
Pod documented
200 0 my $self = shift;
201 0 return $self->set_properties( @_ );
202 }
203  
204 0 ▶sub get_blob_metadata {
Subroutine get_blob_metadata: not called CC=1 SCAR=6.9
Pod documented
205 0 my $self = shift;
206 0 return $self->get_metadata( @_ );
207 }
208  
209 0 ▶sub set_blob_metadata {
Subroutine set_blob_metadata: not called CC=1 SCAR=6.9
Pod documented
210 0 my $self = shift;
211 0 return $self->set_metadata( @_ );
212 }
213  
214 0 ▶sub snapshot_blob {
Subroutine snapshot_blob: not called CC=2 SCAR=17.9
Pod documented
215 0 my ( $self, $path, $params ) = @_;
216 0 $path = $self->_adjust_path( $path );
217 0 my $data = 'comp=snapshot';
218 0 my $options = $params->{ options };
219 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
220 0 $path = "${path}?${data}";
221 0 $params->{ body } = $data;
222 0 return $self->put( $path, $params );
223 }
224  
225 0 ▶sub copy_blob {
Subroutine copy_blob: not called CC=3 SCAR=24.8
Pod documented
226 0 my ( $self, $src, $path, $params ) = @_;
227 0 $path = $self->_adjust_path( $path );
228 0 $src = $self->_adjust_path( $src );
229 0 my $data = '';
230 0 my $account = $self->{ account_name };
231 0 my $protocol = $self->{ protocol };
232 0 my $type = lc( $self->{ type } );
233 0 my $options = $params->{ options };
234 0 ▶ $path .= '?' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
235 0 ▶ $data .= '?' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
236 0 my $url = "${protocol}://${account}.${type}.core.windows.net/${src}";
237 0 $params->{ headers }->{ 'x-ms-copy-source' } = $url;
238 0 $params->{ body } = $data;
239 0 return $self->put( $path, $params );
240 }
241  
242 0 ▶sub abort_copy_blob {
Subroutine abort_copy_blob: not called CC=2 SCAR=17.9
Pod documented
243 0 my ( $self, $path, $params ) = @_;
244 0 $path = $self->_adjust_path( $path );
245 0 my $data = 'comp=copy&copyid=' . $params->{ copyid };
246 0 my $options = $params->{ options };
247 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
248 0 $path = "${path}?${data}";
249 0 $params->{ body } = $data;
250 0 return $self->put( $path, $params );
251 }
252  
253 0 ▶sub delete_blob {
Subroutine delete_blob: not called CC=1 SCAR=6.9
Pod documented
254 0 my $self = shift;
255 0 return $self->remove( @_ );
256 }
257  
258 0 ▶sub lease_blob {
Subroutine lease_blob: not called CC=1 SCAR=6.9
Pod documented
259 0 my $self = shift;
260 0 return $self->lease( @_ );
261 }
262  
263 0 ▶sub put_block {
Subroutine put_block: not called CC=2 SCAR=17.9
Pod documented
264 0 my ( $self, $path, $params ) = @_;
265 0 $path = $self->_adjust_path( $path );
266 0 my $data = 'comp=block&blockid=id' . $params->{ blockid };
267 0 my $options = $params->{ options };
268 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
269 0 $path = "${path}?${data}";
270 0 $params->{ body } = $data;
271 0 return $self->put( $path, $params );
272 }
273  
274 0 ▶sub put_block_list {
Subroutine put_block_list: not called CC=2 SCAR=17.9
Pod documented
275 0 my ( $self, $path, $params ) = @_;
276 0 $path = $self->_adjust_path( $path );
277 0 my $data = 'comp=blocklist';
278 0 my $options = $params->{ options };
279 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
280 0 $path = "${path}?${data}";
281 0 my $BlockList = $params->{ BlockList };
282 0 my $xml = XML::Simple->new;
283 0 my $body = $xml->XMLout( $BlockList, NoAttr => 1, RootName => 'BlockList' );
284 0 $body = '<?xml version="1.0" encoding="utf-8"?>' . "\n${body}";
285 0 $params->{ body } = $body;
286 0 return $self->put( $path, $params );
287 }
288  
289 0 ▶sub get_block_list {
Subroutine get_block_list: not called CC=2 SCAR=17.9
Pod documented
290 0 my ( $self, $path, $params ) = @_;
291 0 $path = $self->_adjust_path( $path );
292 0 my $data = 'comp=blocklist';
293 0 my $options = $params->{ options };
294 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
295 0 $path = "${path}?${data}";
296 0 return $self->get( $path, $params );
297 }
298  
299 0 ▶sub put_page {
Subroutine put_page: not called CC=4 SCAR=30.0
Pod documented
300 0 my ( $self, $path, $params ) = @_;
301 0 $path = $self->_adjust_path( $path );
302 0 my $data = 'comp=page';
303 0 my $options = $params->{ options };
304 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
305 0 $path = "${path}?${data}";
306 0 my $page_write = $params->{ 'page-write' };
307 0 my $range = $params->{ 'range' };
308 0 ▶ $params->{ headers }->{ 'x-ms-page-write' } = $page_write if $page_write;
Branch: 1 branch
BranchTrueFalseTotal
if $page_write 0 0 0
309 0 ▶ $params->{ headers }->{ 'x-ms-range' } = $range if $range;
Branch: 1 branch
BranchTrueFalseTotal
if $range 0 0 0
310 0 $params->{ body } = $data;
311 0 return $self->put( $path, $params );
312 }
313  
314 0 ▶sub get_page_ranges {
Subroutine get_page_ranges: not called CC=2 SCAR=17.9
Pod documented
315 0 my ( $self, $path, $params ) = @_;
316 0 $path = $self->_adjust_path( $path );
317 0 my $data = 'comp=pagelist';
318 0 my $options = $params->{ options };
319 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
320 0 $path = "${path}?${data}";
321 0 return $self->get( $path, $params );
322 }
323  
324 0 ▶sub rename_blob {
Subroutine rename_blob: not called CC=1 SCAR=6.9
Pod documented
325 0 my ( $self, $src, $path, $params ) = @_;
326 0 my $res = $self->copy_blob( $src, $path, $params );
327 0 $self->remove( $src );
328 0 return $res;
329 }
330  
331 0 ▶sub download_container {
Subroutine download_container: not called CC=2 SCAR=17.9
Pod documented
332 0 my ( $self, $path, $dirname, $params ) = @_;
333 0 ▶ if ( $path !~ m!/$! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/$]) 0 0 0
334 0 $path .= '/';
335 }
336 0 $params->{ directory } = 1;
337 0 return $self->download( $path, $dirname, $params );
338 }
339  
340 0 ▶sub download_blob {
Subroutine download_blob: not called CC=1 SCAR=6.9
Pod undocumented
341 0 my $self = shift;
342 0 return $self->download( @_ );
343 }
344  
345 0 ▶sub download {
Subroutine download: not called CC=44 SCAR=75.9
Pod documented
346 0 my ( $self, $path, $filename, $params ) = @_;
347 0 my $dir_info = '';
348 0 ▶ if ( $params->{ directory } || $path =~ m!/$! ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"directory"} or $path =~ m[/$]) 0 0 0
Condition0%0/3
$params->{"directory"} or $path =~ m[/$]
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"directory"} or $path =~ m[/$]
$params->{"directory"} $path =~ m[/$]
Truth table0%0/3
A or B
A= $params->{"directory"}B= $path =~ m[/$]
ABresult
1X1
011
000
349 0 $dir_info = $self->_get_directory_info( $path, $filename, $params );
350 }
351 0 ▶ if ( $dir_info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir_info) 0 0 0
352 # Download blobs of directory
353 0 ▶ my $excludes = $params->{ excludes } || $params->{ exclude };
Condition0%0/3
$params->{'excludes'} || $params->{'exclude'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'excludes'} || $params->{'exclude'}
$params->{'excludes'} $params->{'exclude'}
Truth table0%0/3
A || B
A= $params->{'excludes'}B= $params->{'exclude'}
ABresult
1X1
011
000
354 0 my $container_name = $dir_info->{ container_name };
355 0 my $path = $dir_info->{ path };
356 0 my $blobs = $dir_info->{ blobs };
357 0 my $files = $dir_info->{ files };
358 0 my $download_items;
359 my @removed_items;
360 0 my @removed;
361 0 my $prefix = quotemeta( $path );
362 0 my $base = quotemeta( $filename );
363 0 my @_blobs;
364 0 for my $blob ( @$blobs ) {
365 0 my $name = $blob->{ Name };
366 0 ▶ if ( my $meta = $blob->{ Metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta = $blob->{"Metadata"}) 0 0 0
367 0 ▶ if ( my $original = $meta->{ Path } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $original = $meta->{"Path"}) 0 0 0
368 0 $name = $original;
369 }
370 }
371 0 Encode::_utf8_off( $name );
372 0 ▶ next if $prefix && ( $name !~ /^$prefix/ );
Branch: 1 branch
BranchTrueFalseTotal
if $prefix and not $name =~ /^$prefix/ 0 0 0
Condition0%0/3
$prefix and not $name =~ /^$prefix/
!ll&&!rl&&r
000
MC/DC0%0/2
$prefix and not $name =~ /^$prefix/
$prefix not $name =~ /^$prefix/
Truth table0%0/3
A and not(B)
A= $prefixB= not $name =~ /^$prefix/
ABresult
0X0
100
111
373 0 ▶ if ( $excludes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($excludes) 0 0 0
374 0 my $exclusion;
375 0 for my $check ( @$excludes ) {
376 0 my $search = quotemeta( $check );
377 0 ▶ if ( $name =~ m/$search/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /$search/) 0 0 0
378 0 $exclusion = 1;
379 0 last;
380 }
381 }
382 0 ▶ next if $exclusion;
Branch: 1 branch
BranchTrueFalseTotal
if $exclusion 0 0 0
383 }
384 0 my $real_name = $name;
385 0 ▶ $real_name =~ s/^$prefix// if $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
386 0 ▶ next if _basename( $real_name, '/' ) eq '$$$.$$$';
Branch: 1 branch
BranchTrueFalseTotal
if _basename($real_name, "/") eq "\$\$\$.\$\$\$" 0 0 0
387 0 push ( @_blobs, $real_name );
388 0 my $not_modified;
389 0 my $rel_path = $name;
390 0 ▶ $rel_path =~ s/^$path// if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 0 0 0
391 0 my $file = File::Spec->catfile( $filename, $rel_path );
392 0 ▶ $file =~ s!/!\\!g if ( $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 0 0
393 0 my $q = quotemeta( $file );
394 0 ▶ if ( grep( /^$q$/, @$files ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$q$/, @$files) 0 0 0
395 0 ▶ if ( $params->{ conditional } || $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"conditional"} or $params->{"sync"}) 0 0 0
Condition0%0/3
$params->{"conditional"} or $params->{"sync"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"conditional"} or $params->{"sync"}
$params->{"conditional"} $params->{"sync"}
Truth table0%0/3
A or B
A= $params->{"conditional"}B= $params->{"sync"}
ABresult
1X1
011
000
396 0 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 0 0 0
397 0 my $etag;
398 0 ▶ if ( my $meta = $blob->{ Metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta = $blob->{"Metadata"}) 0 0 0
399 0 $etag = $meta->{ Etag };
400 }
401 0 ▶ if ( $etag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($etag) { } 0 0 0
402 0 my $data = '';
403 0 ▶ open( my $fh, '<', $file ) or die "Can't open '$file'.";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open '${file}'." 0 0 0
404 0 binmode $fh;
405 0 ▶ while ( read $fh, my ( $chunk ), 8192 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $chunk, 8192) 0 0 0
406 0 $data .= $chunk;
407 }
408 0 close $fh;
409 0 my $comp = Digest::MD5::md5_hex( $data );
410 0 ▶ if ( $comp eq $etag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp eq $etag) 0 0 0
411 0 $not_modified = 1;
412 }
413 } else {
414 0 my $mtime = $self->_get_mtime( $blob );
415 0 my @stats = stat $file;
416 0 ▶ if ( $stats[ 9 ] >= $mtime ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stats[9] >= $mtime) 0 0 0
417 0 $not_modified = 1;
418 }
419 }
420 }
421 }
422 }
423 0 ▶ $download_items->{ $blob->{ Name } } = $file unless $not_modified;
Branch: 1 branch
BranchTrueFalseTotal
unless $not_modified 0 0 0
424 }
425 0 for my $item ( @$files ) {
426 0 my $rel_path = $item;
427 0 ▶ $rel_path =~ s!\\!/!g if ( $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 0 0
428 0 $rel_path =~ s/^$base//;
429 0 $rel_path = quotemeta( $rel_path );
430 0 ▶ if (! grep( /^$rel_path$/, @_blobs ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$rel_path$/, @_blobs) 0 0 0
431 0 push ( @removed_items, $item );
432 }
433 }
434 0 my @responses;
435 0 ▶ if ( my $thread = $params->{ use_thread } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $thread = $params->{'use_thread'}) { } 0 0 0
436 0 require Net::Azure::StorageClient::Blob::Thread;
437 0 @responses = Net::Azure::StorageClient::Blob::Thread::download_use_thread(
438 $self,
439 { download_items => $download_items,
440 params => $params,
441 container_name => $container_name,
442 thread => $thread } );
443 } else {
444 0 for my $key ( keys %$download_items ) {
445 0 $params->{ force } = 1;
446 0 my $item;
447 0 ▶ if ( $self->{ container_name } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'container_name'}) { } 0 0 0
448 0 $item = $key;
449 } else {
450 0 $item = $container_name . '/' . $key;
451 }
452 0 $params->{ directory } = undef;
453 my $res = $self->download( $item,
454 0 $download_items->{ $key },
455 $params );
456 0 push ( @responses, $res );
457 }
458 }
459 0 ▶ if ( $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"sync"}) 0 0 0
460 0 my $not_remove = $params->{ not_remove };
461 0 for my $remove( @removed_items ) {
462 0 ▶ if ( $not_remove ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($not_remove) 0 0 0
463 0 my $exclusion;
464 0 for my $check ( @$not_remove ) {
465 0 my $search = quotemeta( $check );
466 0 ▶ if ( $remove =~ m/$search/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove =~ /$search/) 0 0 0
467 0 $exclusion = 1;
468 0 last;
469 }
470 }
471 0 ▶ next if $exclusion;
Branch: 1 branch
BranchTrueFalseTotal
if $exclusion 0 0 0
472 }
473 0 ▶ if ( unlink $remove ) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlink $remove) 0 0 0
474 0 push ( @removed, $remove );
475 }
476 }
477 }
478 0 ▶ if ( $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"sync"}) 0 0 0
479 0 my $response = { responses => \@responses,
480 removed_files => \@removed };
481 0 return $response;
482 }
483 0 ▶ return \@responses if @responses;
Branch: 1 branch
BranchTrueFalseTotal
if @responses 0 0 0
484 return
485 0 }
486 0 $params->{ filename } = $filename;
487 0 return $self->_get( $path, $params );
488 }
489  
490 0 ▶sub upload_container {
Subroutine upload_container: not called CC=2 SCAR=17.9
Pod undocumented
491 0 my ( $self, $path, $dirname, $params ) = @_;
492 0 ▶ if ( $path !~ m!/$! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/$]) 0 0 0
493 0 $path .= '/';
494 }
495 0 return $self->upload( $path, $dirname, $params );
496 }
497  
498 0 ▶sub upload_blob {
Subroutine upload_blob: not called CC=1 SCAR=6.9
Pod undocumented
499 0 my $self = shift;
500 0 return $self->upload( @_ );
501 }
502  
503 0 ▶sub upload {
Subroutine upload: not called CC=43 SCAR=75.5
Pod documented
504 0 my ( $self, $path, $filename, $params ) = @_;
505 0 my $dir_info = '';
506 0 ▶ if ( $params->{ directory } || $path =~ m!/$! ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"directory"} or $path =~ m[/$]) 0 0 0
Condition0%0/3
$params->{"directory"} or $path =~ m[/$]
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"directory"} or $path =~ m[/$]
$params->{"directory"} $path =~ m[/$]
Truth table0%0/3
A or B
A= $params->{"directory"}B= $path =~ m[/$]
ABresult
1X1
011
000
507 0 $dir_info = $self->_get_directory_info( $path, $filename, $params );
508 }
509 0 ▶ if ( $dir_info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir_info) 0 0 0
510 # Upload files of directory
511 0 ▶ my $excludes = $params->{ excludes } || $params->{ exclude };
Condition0%0/3
$params->{'excludes'} || $params->{'exclude'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'excludes'} || $params->{'exclude'}
$params->{'excludes'} $params->{'exclude'}
Truth table0%0/3
A || B
A= $params->{'excludes'}B= $params->{'exclude'}
ABresult
1X1
011
000
512 0 my $container_name = $dir_info->{ container_name };
513 0 my $path = $dir_info->{ path };
514 0 my $blobs = $dir_info->{ blobs };
515 0 my $files = $dir_info->{ files };
516 0 my @upload_items;
517 my @not_modified_items;
518 0 my @removed_items;
519 0 my $prefix = quotemeta( $path );
520 0 my $search_dir = quotemeta( $filename );
521 0 ▶ if ( $params->{ conditional } || $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'conditional'} or $params->{'sync'}) { } 0 0 0
Condition0%0/3
$params->{"conditional"} or $params->{"sync"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"conditional"} or $params->{"sync"}
$params->{"conditional"} $params->{"sync"}
Truth table0%0/3
A or B
A= $params->{"conditional"}B= $params->{"sync"}
ABresult
1X1
011
000
522 0 for my $blob ( @$blobs ) {
523 0 my $name = $blob->{ Name };
524 0 ▶ if ( my $meta = $blob->{ Metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta = $blob->{"Metadata"}) 0 0 0
525 0 ▶ if ( my $original = $meta->{ Path } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $original = $meta->{"Path"}) 0 0 0
526 0 $name = $original;
527 }
528 }
529 0 ▶ next if ( _basename( $name, '/' ) eq '$$$.$$$' );
Branch: 1 branch
BranchTrueFalseTotal
if _basename($name, "/") eq "\$\$\$.\$\$\$" 0 0 0
530 0 ▶ next if $prefix && ( $name !~ /^$prefix/ );
Branch: 1 branch
BranchTrueFalseTotal
if $prefix and not $name =~ /^$prefix/ 0 0 0
Condition0%0/3
$prefix and not $name =~ /^$prefix/
!ll&&!rl&&r
000
MC/DC0%0/2
$prefix and not $name =~ /^$prefix/
$prefix not $name =~ /^$prefix/
Truth table0%0/3
A and not(B)
A= $prefixB= not $name =~ /^$prefix/
ABresult
0X0
100
111
531 0 my $real_name = $name;
532 0 ▶ $real_name =~ s/$prefix// if $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
533 0 my $file = File::Spec->catfile( $filename, $real_name );
534 0 ▶ $file =~ s!/!\\!g if ( $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 0 0
535 0 my $q = quotemeta( $file );
536 0 ▶ if ( grep( /^$q$/, @$files ) || ( -f $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$q$/, @$files or -f $file) { } 0 0 0
Condition0%0/3
grep /^$q$/, @$files or -f $file
l!l&&r!l&&!r
000
MC/DC0%0/2
grep /^$q$/, @$files or -f $file
grep /^$q$/, @$files -f $file
Truth table0%0/3
A or B
A= grep /^$q$/, @$filesB= -f $file
ABresult
1X1
011
000
537 0 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 0 0 0
538 0 my $etag;
539 0 ▶ if ( my $meta = $blob->{ Metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta = $blob->{"Metadata"}) 0 0 0
540 0 $etag = $meta->{ Etag };
541 }
542 0 ▶ if ( $etag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($etag) { } 0 0 0
543 0 my $data = '';
544 0 ▶ open( my $fh, '<', $file) or die "Can't open '$file'.";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open '${file}'." 0 0 0
545 0 binmode $fh;
546 0 ▶ while ( read $fh, my ( $chunk ), 8192 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $chunk, 8192) 0 0 0
547 0 $data .= $chunk;
548 }
549 0 close $fh;
550 0 $params->{ contents }->{ $filename } = $data;
551 0 my $comp = Digest::MD5::md5_hex( $data );
552 0 ▶ if ( $comp eq $etag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp eq $etag) 0 0 0
553 0 push ( @not_modified_items, _encode_path( $file ) );
554 }
555 } else {
556 0 my $mtime = $self->_get_mtime( $blob );
557 0 my @stats = stat $file;
558 0 ▶ push ( @not_modified_items, $file )
Branch: 1 branch
BranchTrueFalseTotal
if $stats[9] <= $mtime 0 0 0
559 if ( $stats[ 9 ] <= $mtime );
560 }
561 }
562 } else {
563 0 ▶ push ( @removed_items, $name ) if ( $params->{ sync } );
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"sync"} 0 0 0
564 }
565 }
566 0 for my $item ( @$files ) {
567 0 my $q = quotemeta( _encode_path( $item ) );
568 0 ▶ if (! grep( /^$q$/, @not_modified_items ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$q$/, @not_modified_items) 0 0 0
569 0 push ( @upload_items, $item );
570 }
571 }
572 } else {
573 0 @upload_items = @$files;
574 }
575 0 my @responses;
576 my $uploads;
577 0 for my $file ( @upload_items ) {
578 0 ▶ if ( $excludes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($excludes) 0 0 0
579 0 my $exclusion;
580 0 for my $check ( @$excludes ) {
581 0 my $search = quotemeta( $check );
582 0 ▶ if ( $file =~ m/$search/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /$search/) 0 0 0
583 0 $exclusion = 1;
584 0 last;
585 }
586 }
587 0 ▶ next if $exclusion;
Branch: 1 branch
BranchTrueFalseTotal
if $exclusion 0 0 0
588 }
589 0 my $item = $file;
590 0 $item =~ s/^$search_dir//;
591 0 ▶ if ( $self->{ container_name } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'container_name'}) { } 0 0 0
592 0 $item = $path . $item;
593 } else {
594 0 $item = $container_name . '/' . $path . $item;
595 }
596 0 ▶ if ( $params->{ use_thread } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'use_thread'}) { } 0 0 0
597 0 $uploads->{ $item } = $file;
598 } else {
599 0 $params->{ force } = 1;
600 0 my $res = $self->upload( $item, $file, $params );
601 0 push ( @responses, $res );
602 }
603 }
604 0 ▶ if ( my $thread = $params->{ use_thread } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $thread = $params->{"use_thread"}) 0 0 0
605 0 require Net::Azure::StorageClient::Blob::Thread;
606 0 @responses = Net::Azure::StorageClient::Blob::Thread::upload_use_thread(
607 $self,
608 { upload_items => $uploads,
609 params => $params,
610 thread => $thread } );
611 }
612 0 ▶ if ( $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"sync"}) 0 0 0
613 0 my $not_remove = $params->{ not_remove };
614 0 for my $item ( @removed_items ) {
615 0 ▶ if (! $self->{ container_name } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"container_name"}) 0 0 0
616 0 $item = $container_name . '/' . $item;
617 }
618 0 ▶ if ( $not_remove ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($not_remove) 0 0 0
619 0 my $exclusion;
620 0 for my $check ( @$not_remove ) {
621 0 my $search = quotemeta( $check );
622 0 ▶ if ( $item =~ m/$search/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /$search/) 0 0 0
623 0 $exclusion = 1;
624 0 last;
625 }
626 }
627 0 ▶ next if $exclusion;
Branch: 1 branch
BranchTrueFalseTotal
if $exclusion 0 0 0
628 }
629 0 my $res = $self->remove( $item, $params );
630 0 push ( @responses, $res );
631 }
632 }
633 0 ▶ return \@responses if @responses;
Branch: 1 branch
BranchTrueFalseTotal
if @responses 0 0 0
634 return
635 0 }
636 0 $params->{ filename } = $filename;
637 0 return $self->_put( $path, $params );
638 }
639  
640 0 ▶sub sync {
Subroutine sync: not called CC=5 SCAR=34.0
Pod documented
641 0 my ( $self, $path, $directory, $params ) = @_;
642 0 ▶ if ( $path !~ m!/$! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/$]) 0 0 0
643 0 $path .= '/';
644 }
645 0 ▶ my $separator = $^O eq 'MSWin32' ? '\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
646 0 ▶ if ( $directory !~ m!$separator$! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($directory =~ /$separator$/) 0 0 0
647 0 $directory .= $separator;
648 }
649 0 ▶ my $direction = $params->{ direction } || 'upload';
Condition0%0/2
$params->{'direction'} || 'upload'
l!l
00
MC/DC0%0/1
$params->{'direction'} || 'upload'
$params->{'direction'}
Truth table0%0/2
A
A= $params->{'direction'}
Aresult
11
00
650 0 $params->{ conditional } = 1;
651 0 $params->{ sync } = 1;
652 0 $params->{ directory } = 1;
653 0 return $self->$direction( $path, $directory, $params );
654 }
655  
656 0 ▶sub list {
Subroutine list: not called CC=14 SCAR=53.5
Pod undocumented
657 0 my ( $self, $path, $params ) = @_;
658 0 ▶ $path = '' unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 0 0
659 0 $path =~ s!^/!!;
660 0 ▶ if ( $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) { } 0 0 0
661 0 $path .= '?restype=container&comp=list'; # &maxresults=n
662 } else {
663 0 $path .= '?comp=list';
664 }
665 0 my $options = $params->{ options };
666 0 ▶ $path .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
667 0 my $res = $self->get( $path, $params );
668 0 my @responses;
669 0 push ( @responses, $res );
670 0 ▶ if ( $res->code != 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code != 200) 0 0 0
671 0 ▶ return $res unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
672 0 return \@responses;
673 }
674 0 my $marker;
675 0 my $xml = XML::Simple->new;
676 0 my $data = $res->content;
677 0 my $list = $xml->XMLin( $data );
678 0 $marker = $list->{ NextMarker };
679 0 ▶ $marker = undef if ( ( ref $marker ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $marker eq "HASH" 0 0 0
680 0 ▶ if (! $marker ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $marker) { } 0 0 0
681 0 ▶ return $res unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
682 } else {
683 0 ▶ while ( $marker ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($marker) 0 0 0
684 0 $marker =~ s!([^a-zA-Z0-9_.~-])!uc sprintf "%%%02x", ord($1)!eg;
685 0 my $next = $path . '&marker=' . $marker;
686 0 my $res = $self->get( $next, $params );
687 0 ▶ if ( $res->code != 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code != 200) 0 0 0
688 0 ▶ return @responses if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
689 0 return \@responses;
690 }
691 0 push ( @responses, $res );
692 0 my $xml = XML::Simple->new;
693 0 my $data = $res->content;
694 0 my $n_list = $xml->XMLin( $data );
695 0 $marker = $n_list->{ NextMarker };
696 0 ▶ $marker = undef if ( ( ref $marker ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $marker eq "HASH" 0 0 0
697 }
698 }
699 0 ▶ return @responses if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
700 0 return \@responses;
701 }
702  
703 0 ▶sub get_metadata {
Subroutine get_metadata: not called CC=3 SCAR=24.8
Pod undocumented
704 0 my ( $self, $path, $params ) = @_;
705 0 $params->{ 'method' } = 'HEAD';
706 0 ▶ my $options = $params->{ options } || '';
Condition0%0/2
$params->{'options'} || ''
l!l
00
MC/DC0%0/1
$params->{'options'} || ''
$params->{'options'}
Truth table0%0/2
A
A= $params->{'options'}
Aresult
11
00
707 0 ▶ $options .= '&' if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
708 0 $options .= 'comp=metadata';
709 0 $params->{ options } = $options;
710 0 return $self->_get( $path, $params );
711 }
712  
713 0 ▶sub get_properties {
Subroutine get_properties: not called CC=1 SCAR=6.9
Pod undocumented
714 0 my ( $self, $path, $params ) = @_;
715 0 $params->{ 'method' } = 'HEAD';
716 0 return $self->_get( $path, $params );
717 }
718  
719 0 ▶sub set_properties {
Subroutine set_properties: not called CC=4 SCAR=30.0
Pod undocumented
720 0 my ( $self, $path, $params ) = @_;
721 0 $path = $self->_adjust_path( $path );
722 0 my $options = 'comp=properties';
723 0 ▶ $options .= '&' . $params->{ options } if $params->{ options };
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"options"} 0 0 0
724 0 $params->{ options } = $options;
725 0 my $properties = $params->{ properties };
726 0 for my $key ( keys %$properties ) {
727 0 my $property = $key;
728 0 ▶ if ( $key !~ m/^x\-ms\-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /^x\-ms\-/) 0 0 0
729 0 $property = 'x-ms-' . $property;
730 }
731 0 $params->{ headers }->{ $property } = $properties->{ $property };
732 }
733 0 $params->{ body } = $options;
734 0 return $self->put( $path, $params );
735 }
736  
737 0 ▶sub set_metadata {
Subroutine set_metadata: not called CC=5 SCAR=34.0
Pod undocumented
738 0 my ( $self, $path, $params ) = @_;
739 0 $path = $self->_adjust_path( $path );
740 0 my $data = 'comp=metadata';
741 0 ▶ if ( $path !~ m!/! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/]) 0 0 0
742 0 $data = 'restype=container&' . $data;
743 }
744 0 my $options = $params->{ options };
745 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
746 0 $path = "${path}?${data}";
747 0 my $metadata = $params->{ metadata };
748 0 for my $key ( keys %$metadata ) {
749 0 my $meta = $key;
750 0 ▶ if ( $key !~ m/^x\-ms\-meta\-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /^x\-ms\-meta\-/) 0 0 0
751 0 $meta = 'x-ms-meta-' . $meta;
752 }
753 0 $params->{ headers }->{ $meta } = $metadata->{ $key };
754 }
755 0 $params->{ body } = $data;
756 0 return $self->put( $path, $params );
757 }
758  
759 0 ▶sub remove {
Subroutine remove: not called CC=4 SCAR=30.0
Pod undocumented
760 0 my ( $self, $path, $params ) = @_;
761 0 $path = $self->_adjust_path( $path );
762 0 ▶ if ( $path =~ /\%/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\%/) 0 0 0
763 0 $path = _encode_path( $path, '/' );
764 }
765 0 ▶ if ( $path !~ m!/! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/]) 0 0 0
766 0 return $self->delete_container( $path, $params );
767 }
768 0 my $options = $params->{ options };
769 0 ▶ $path .= '?' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
770 0 return $self->delete( $path, $params );
771 }
772  
773 0 ▶sub lease {
Subroutine lease: not called CC=5 SCAR=34.0
Pod undocumented
774 0 my ( $self, $path, $params ) = @_;
775 0 $path = $self->_adjust_path( $path );
776 0 my $data = 'comp=lease';
777 0 ▶ if ( $path !~ m!/! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/]) 0 0 0
778 0 $data = 'restype=container&' . $data;
779 }
780 0 my $options = $params->{ options };
781 0 ▶ $data .= '&' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
782 0 $path = "${path}?${data}";
783 0 my $lease_parameters = $params->{ lease_parameters };
784 0 for my $key ( keys %$lease_parameters ) {
785 0 my $parameter = $key;
786 0 ▶ if ( $key !~ m/^x\-ms\-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /^x\-ms\-/) 0 0 0
787 0 $parameter = 'x-ms-' . $parameter;
788 }
789 0 $params->{ headers }->{ $parameter } = $lease_parameters->{ $key };
790 }
791 0 $params->{ body } = $data;
792 0 return $self->put( $path, $params );
793 }
794  
795 0 ▶sub _get {
Subroutine _get: not called CC=23 SCAR=63.1
796 0 my ( $self, $path, $params ) = @_;
797 0 my $orig_path = $path;
798 0 $path = $self->_adjust_path( $path );
799 0 my $filename;
800 0 ▶ if ( $params && $params->{ filename } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params and $params->{"filename"}) 0 0 0
Condition0%0/3
$params and $params->{"filename"}
!ll&&!rl&&r
000
MC/DC0%0/2
$params and $params->{"filename"}
$params $params->{"filename"}
Truth table0%0/3
A and B
A= $paramsB= $params->{"filename"}
ABresult
0X0
100
111
801 0 $filename = $params->{ filename };
802 }
803 0 ▶ if ( $filename && ( $params->{ conditional } || $params->{ sync } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename and $params->{"conditional"} || $params->{"sync"}) 0 0 0
Condition0%0/6
$filename and $params->{"conditional"} || $params->{"sync"}
!ll&&!rl&&r
000
$params->{"conditional"} or $params->{"sync"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$filename and $params->{"conditional"} || $params->{"sync"}
$filename $params->{"conditional"} $params->{"sync"}
Truth table0%0/4
A and B or C
A= $filenameB= $params->{"conditional"}C= $params->{"sync"}
ABCresult
0XX0
1000
11X1
1011
804 0 ▶ if (! $params->{ force } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"force"}) 0 0 0
805 0 $params->{ compare } = 'from';
806 0 my $metadata = $self->_do_conditional( $orig_path, $filename, $params );
807 0 ▶ return $metadata if $metadata;
Branch: 1 branch
BranchTrueFalseTotal
if $metadata 0 0 0
808 }
809 }
810 0 my $method = $params->{ 'method' };
811 0 my $separator = '?';
812 0 ▶ if ( ( $path !~ m!/! ) && ( $method && ( $method eq 'HEAD' ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $path =~ m[/] and ($method and $method eq "HEAD")) 0 0 0
Condition0%0/6
not $path =~ m[/] and ($method and $method eq "HEAD")
!ll&&!rl&&r
000
$method and $method eq "HEAD"
!ll&&!rl&&r
000
MC/DC0%0/3
not $path =~ m[/] and ($method and $method eq "HEAD")
not $path =~ m[/] $method $method eq "HEAD"
Truth table0%0/4
not(A) and B and C
A= not $path =~ m[/]B= $methodC= $method eq "HEAD"
ABCresult
0XX0
10X0
1100
1111
813 0 $path .= '?restype=container';
814 0 $separator = '&';
815 }
816 0 ▶ $method = 'GET' unless $method;
Branch: 1 branch
BranchTrueFalseTotal
unless $method 0 0 0
817 0 my $options = $params->{ options };
818 0 ▶ $path .= $separator . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
819 0 $params->{ 'method' } = $method;
820 0 ▶ if ( $path =~ /\%/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\%/) 0 0 0
821 0 $path = _encode_path( $path, '/' );
822 }
823 0 my $res = $self->request( $method, $path, $params );
824 0 ▶ if ( $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) 0 0 0
825 0 ▶ if ( $res->code == 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 200) 0 0 0
826 0 my $content = $res->content;
827 0 my $dir = File::Basename::dirname( $filename );
828 0 ▶ if (! -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
829 0 File::Path::mkpath( $dir );
830 }
831 0 ▶ if ( -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) 0 0 0
832 0 ▶ open( my $fh, '>', $filename) or die "Can't open '$filename'.";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or die "Can't open '${filename}'." 0 0 0
833 0 print $fh $content;
834 0 close $fh ;
835 0 ▶ if ( $params->{ conditional } || $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"conditional"} or $params->{"sync"}) 0 0 0
Condition0%0/3
$params->{"conditional"} or $params->{"sync"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"conditional"} or $params->{"sync"}
$params->{"conditional"} $params->{"sync"}
Truth table0%0/3
A or B
A= $params->{"conditional"}B= $params->{"sync"}
ABresult
1X1
011
000
836 0 my $mtime;
837 0 ▶ if( $res->headers->{ 'x-ms-meta-mtime' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->headers->{'x-ms-meta-mtime'}) { } 0 0 0
838 0 $mtime = $res->headers->{ 'x-ms-meta-mtime' };
839 } else {
840 0 $mtime = $res->headers->{ 'last-modified' };
841 0 $mtime = str2time( $mtime );
842 }
843 0 ▶ if ( -f $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) 0 0 0
844 0 my @stat = stat $filename;
845 0 my $atime = $stat[ 8 ];
846 0 utime $atime, $mtime, $filename;
847 }
848 }
849 }
850 }
851 }
852 0 return $res;
853 }
854  
855 0 ▶sub _put {
Subroutine _put: not called CC=20 SCAR=60.4
856 0 my ( $self, $path, $data, $params ) = @_;
857 0 my $orig_path = $path;
858 0 ▶ if ( ref $data eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "HASH") 0 0 0
859 0 $params = $data;
860 }
861 0 $path = $self->_adjust_path( $path );
862 0 my $filename = $params->{ filename };
863 0 my $options = $params->{ options };
864 0 ▶ $path .= '?' . $options if $options;
Branch: 1 branch
BranchTrueFalseTotal
if $options 0 0 0
865 0 ▶ my $blob_type = $params->{ blob_type } || 'BlockBlob';
Condition0%0/2
$params->{'blob_type'} || 'BlockBlob'
l!l
00
MC/DC0%0/1
$params->{'blob_type'} || 'BlockBlob'
$params->{'blob_type'}
Truth table0%0/2
A
A= $params->{'blob_type'}
Aresult
11
00
866 0 $params->{ headers }->{ 'x-ms-blob-type' } = $blob_type;
867 0 ▶ if (! $params->{ no_metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"no_metadata"}) 0 0 0
868 0 my $mimetype = $params->{ 'content-type' };
869 0 ▶ if (! $mimetype ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mimetype) 0 0 0
870 0 require Net::Azure::StorageClient::MIMEType;
871 0 $mimetype = Net::Azure::StorageClient::MIMEType::get_mimetype( $path );
872 }
873 0 $params->{ headers }->{ 'content-type' } = $mimetype;
874 }
875 0 ▶ if ( $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) 0 0 0
876 0 $data = '';
877 0 ▶ if ( -d $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $filename) 0 0 0
878 0 $filename = File::Spec->catfile( $filename, _basename( $path, '/' ) );
879 }
880 0 ▶ if ( $params->{ contents } && $params->{ contents }->{ $filename } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'contents'} and $params->{'contents'}{$filename}) { } 0 0 0
Condition0%0/3
$params->{"contents"} and $params->{"contents"}{$filename}
!ll&&!rl&&r
000
MC/DC0%0/2
$params->{"contents"} and $params->{"contents"}{$filename}
$params->{"contents"} $params->{"contents"}{$filename}
Truth table0%0/3
A and B
A= $params->{"contents"}B= $params->{"contents"}{$filename}
ABresult
0X0
100
111
881 0 $data = $params->{ contents }->{ $filename };
882 } else {
883 0 ▶ open( my $fh, '<', $filename ) or die "Can't open '$filename'.";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Can't open '${filename}'." 0 0 0
884 0 binmode $fh;
885 0 ▶ while ( read $fh, my ( $chunk ), 8192 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $chunk, 8192) 0 0 0
886 0 $data .= $chunk;
887 }
888 0 close $fh;
889 }
890 0 ▶ if ( $params->{ conditional } || $params->{ sync } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"conditional"} or $params->{"sync"}) 0 0 0
Condition0%0/3
$params->{"conditional"} or $params->{"sync"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"conditional"} or $params->{"sync"}
$params->{"conditional"} $params->{"sync"}
Truth table0%0/3
A or B
A= $params->{"conditional"}B= $params->{"sync"}
ABresult
1X1
011
000
891 0 ▶ if (! $params->{ force } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"force"}) 0 0 0
892 0 $params->{ compare } = 'to';
893 0 $params->{ content } = $data;
894 0 my $metadata = $self->_do_conditional( $orig_path, $filename, $params );
895 0 ▶ return $metadata if $metadata;
Branch: 1 branch
BranchTrueFalseTotal
if $metadata 0 0 0
896 }
897 }
898 0 ▶ if ( -f $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) 0 0 0
899 0 my @stats = stat $filename;
900 0 ▶ if (! $params->{ no_metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"no_metadata"}) 0 0 0
901 0 $params->{ headers }->{ 'x-ms-meta-mtime' } = $stats[ 9 ];
902 0 $params->{ headers }->{ 'x-ms-meta-mode' } = sprintf( '%o', $stats[ 2 ] ); # oct()
903 0 $params->{ headers }->{ 'x-ms-meta-uid' } = $stats[ 4 ];
904 0 $params->{ headers }->{ 'x-ms-meta-gid' } = $stats[ 5 ];
905 0 my $etag = Digest::MD5::md5_hex( $data );
906 0 $params->{ headers }->{ 'x-ms-meta-etag' } = $etag;
907 # Custom header for set timestamp,etag and permission.
908 }
909 }
910 }
911 0 $params->{ body } = $data;
912 0 ▶ if ( $path =~ /\%/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\%/) 0 0 0
913 0 my $encoded = _encode_path( $path );
914 0 ▶ if ( $encoded ne $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoded ne $path) 0 0 0
915 0 my $name = $path;
916 0 $name =~ s!^.*?/(.*)$!$1!;
917 0 $params->{ headers }->{ 'x-ms-meta-path' } = $name;
918 0 $path = $encoded;
919 }
920 }
921 0 return $self->put( $path, $params );
922 }
923  
924 0 ▶sub _do_conditional {
Subroutine _do_conditional: not called CC=17 SCAR=57.2
925 0 my ( $self, $path, $filename, $params ) = @_;
926 0 ▶ return unless -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 0 0
927 0 my $metadata = $self->get_metadata( $path );
928 0 ▶ if ( $metadata->code == 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metadata->code == 200) 0 0 0
929 0 my $conditional;
930 0 ▶ if ( -f $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) 0 0 0
931 0 my $etag = $metadata->headers->{ 'x-ms-meta-etag' };
932 0 my $mtime = $metadata->headers->{ 'x-ms-meta-mtime' };
933 0 my $data = $params->{ content };
934 0 ▶ if ( $etag && (! defined( $data ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($etag and not defined $data) 0 0 0
Condition0%0/3
$etag and not defined $data
!ll&&!rl&&r
000
MC/DC0%0/2
$etag and not defined $data
$etag not defined $data
Truth table0%0/3
A and not(B)
A= $etagB= not defined $data
ABresult
0X0
100
111
935 0 $data = '';
936 0 ▶ open( my $fh, '<', $filename) or die "Can't open '$filename'.";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Can't open '${filename}'." 0 0 0
937 0 binmode $fh;
938 0 ▶ while ( read $fh, my ( $chunk ), 8192 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $chunk, 8192) 0 0 0
939 0 $data .= $chunk;
940 }
941 0 close $fh;
942 }
943 0 ▶ if ( $etag && defined( $data ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($etag and defined $data) { } 0 0 0
elsif ($mtime) { } 0 0 0
Condition0%0/3
$etag and defined $data
!ll&&!rl&&r
000
MC/DC0%0/2
$etag and defined $data
$etag defined $data
Truth table0%0/3
A and B
A= $etagB= defined $data
ABresult
0X0
100
111
944 0 my $comp = Digest::MD5::md5_hex( $data );
945 0 ▶ if ( $comp eq $etag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp eq $etag) 0 0 0
946 0 $conditional = 1;
947 }
948 } elsif ( $mtime ) {
949 0 my @stats = stat $filename;
950 0 my $compare = $params->{ compare };
951 0 my $conditional;
952 0 ▶ if ( ( $compare eq 'to' ) && ( $stats[ 9 ] <= $mtime ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($compare eq 'to' and $stats[9] <= $mtime) { } 0 0 0
elsif ($compare eq 'from' and $stats[9] >= $mtime) { } 0 0 0
Condition0%0/3
$compare eq "to" and $stats[9] <= $mtime
!ll&&!rl&&r
000
MC/DC0%0/2
$compare eq "to" and $stats[9] <= $mtime
$compare eq "to" $stats[9] <= $mtime
Truth table0%0/3
A and B
A= $compare eq "to"B= $stats[9] <= $mtime
ABresult
0X0
100
111
953 0 $conditional = 1;
954 ▶ } elsif ( ( $compare eq 'from' ) && ( $stats[ 9 ] >= $mtime ) ) {
Condition0%0/3
$compare eq "from" and $stats[9] >= $mtime
!ll&&!rl&&r
000
MC/DC0%0/2
$compare eq "from" and $stats[9] >= $mtime
$compare eq "from" $stats[9] >= $mtime
Truth table0%0/3
A and B
A= $compare eq "from"B= $stats[9] >= $mtime
ABresult
0X0
100
111
955 0 $conditional = 1;
956 }
957 }
958 }
959 0 ▶ if ( $conditional ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conditional) 0 0 0
960 0 $metadata->code( 304 );
961 0 $metadata->message( 'Not Modified' );
962 0 return $metadata;
963 }
964 }
965 return
966 0 }
967  
968 0 ▶sub _get_mtime {
Subroutine _get_mtime: not called CC=4 SCAR=30.0
969 0 my $self = shift;
970 0 my $blob = shift;
971 0 my $mtime;
972 0 ▶ if ( my $meta = $blob->{ Metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta = $blob->{"Metadata"}) 0 0 0
973 0 ▶ if ( my $blob_mtime = $meta->{ Mtime } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $blob_mtime = $meta->{"Mtime"}) 0 0 0
974 0 $mtime = $blob_mtime;
975 }
976 }
977 0 ▶ if (! $mtime ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mtime) 0 0 0
978 0 $mtime = $blob->{ Properties }->{ 'Last-Modified' };
979 0 $mtime = str2time( $mtime );
980 }
981 0 return $mtime;
982 }
983  
984 0 ▶sub _get_directory_info {
Subroutine _get_directory_info: not called CC=16 SCAR=56.1
985 0 my ( $self, $path, $dirname, $params ) = @_;
986 0 $path = $self->_adjust_path( $path );
987 0 ▶ if ( $path !~ m!/! ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/]) 0 0 0
988 0 $path .= '/';
989 }
990 0 ▶ if ( $path =~ m!/$! ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[/$]) 0 0 0
991 # Upload or Download directory
992 0 ▶ $path = '' unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 0 0
993 0 $path =~ s!^/!!;
994 0 my $container_name = $self->{ container_name };
995 0 ▶ if (! $container_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $container_name) { } 0 0 0
996 0 my @split_path = split( /\//, $path );
997 0 $container_name = $split_path[ 0 ];
998 0 $path =~ s!^$container_name/!!;
999 } else {
1000 0 $path =~ s/^$container_name//;
1001 0 $path =~ s!^/!!;
1002 }
1003 0 ▶ return unless $container_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $container_name 0 0 0
1004 0 my $dir = _basename( $path, '/', 'dirname' );
1005 0 ▶ if ( $dir eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq '.') { } 0 0 0
1006 0 $dir = $path;
1007 } else {
1008 0 $dir .= '/';
1009 }
1010 0 my $options = 'include=metadata';
1011 0 ▶ if ( $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 0 0 0
1012 0 $options .= '&prefix=' . $dir;
1013 }
1014 0 my $blobs;
1015 0 my $list_params = { options => $options, headers => $params->{headers} };
1016 0 my $res = $self->list( $container_name, $list_params );
1017 0 my $responses;
1018 0 ▶ if ( ( ref $res ) ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res ne 'ARRAY') { } 0 0 0
1019 0 push ( @$responses, $res );
1020 } else {
1021 0 $responses = $res;
1022 }
1023 0 for my $res ( @$responses ) {
1024 0 ▶ if ( $res->code != 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code != 200) 0 0 0
1025 0 die $res->message;
1026 }
1027 0 my $data = $res->content;
1028 0 my $xml = XML::Simple->new;
1029 0 my $list = $xml->XMLin( $data );
1030 0 ▶ if ( my $blob_list = $list->{ Blobs }->{ Blob } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $blob_list = $list->{"Blobs"}{"Blob"}) 0 0 0
1031 0 ▶ if ( ref( $blob_list ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $blob_list eq 'HASH') { } 0 0 0
1032 0 push ( @$blobs, $blob_list );
1033 } else {
1034 0 push ( @$blobs, @$blob_list );
1035 }
1036 }
1037 }
1038 0 my $files;
1039 0 ▶ if ( -d $dirname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dirname) 0 0 0
1040 0 ▶ my $separator = $^O eq 'MSWin32' ? '\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
1041 0 my $search_base = quotemeta( $dirname . $separator );
1042 0 eval {
1043 0 ▶ File::Find::find( sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1044 0 my $file = $File::Find::name;
1045 0 $file =~ s/^$search_base//;
1046 0 my $basename = File::Basename::basename( $_ );
1047 0 ▶ if ( $params->{ include_invisible } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'include_invisible'}) { } 0 0 0
1048 0 ▶ push @$files, $file
Branch: 1 branch
BranchTrueFalseTotal
if -f $File::Find::name and not $basename =~ /^\.{1,}$/ 0 0 0
Condition0%0/3
-f $File::Find::name and not $basename =~ /^\.{1,}$/
!ll&&!rl&&r
000
MC/DC0%0/2
-f $File::Find::name and not $basename =~ /^\.{1,}$/
-f $File::Find::name not $basename =~ /^\.{1,}$/
Truth table0%0/3
A and not(B)
A= -f $File::Find::nameB= not $basename =~ /^\.{1,}$/
ABresult
0X0
100
111
1049 if ( -f $File::Find::name
1050 and $basename !~ m/^\.{1,}$/ );
1051 } else {
1052 0 my @fileparse = File::Spec->splitdir( $file );
1053 # push( @$files, $file ) if ( -f $File::Find::name and $basename !~ /^\./ );
1054 0 ▶ push @$files, $file
Branch: 1 branch
BranchTrueFalseTotal
if -f $File::Find::name and not grep(/^\./, @fileparse) 0 0 0
Condition0%0/3
-f $File::Find::name and not grep(/^\./, @fileparse)
!ll&&!rl&&r
000
MC/DC0%0/2
-f $File::Find::name and not grep(/^\./, @fileparse)
-f $File::Find::name not grep(/^\./, @fileparse)
Truth table0%0/3
A and not(B)
A= -f $File::Find::nameB= not grep(/^\./, @fileparse)
ABresult
0X0
100
111
1055 if ( -f $File::Find::name
1056 and (! grep( /^\./, @fileparse ) ) );
1057 } },
1058 0 $dirname )
1059 };
1060 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1061 0 die $@;
1062 }
1063 }
1064 0 my $dir_info = { container_name => $container_name,
1065 path => $path,
1066 blobs => $blobs,
1067 files => $files };
1068 0 return $dir_info;
1069 }
1070 return
1071 0 }
1072  
1073 0 ▶sub _encode_path {
Subroutine _encode_path: not called CC=4 SCAR=30.0
1074 0 my ( $filename, $separator ) = @_;
1075 0 Encode::_utf8_off( $filename );
1076 0 my @fileparse;
1077 0 ▶ if (! $separator ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $separator) { } 0 0 0
1078 0 ▶ $separator = $^O eq 'MSWin32' ? '\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
1079 0 @fileparse = File::Spec->splitdir( $filename );
1080 } else {
1081 0 my $q = quotemeta( $separator );
1082 0 @fileparse = split( /$q/, $filename );
1083 }
1084 0 my @paths;
1085 0 for my $path ( @fileparse ) {
1086 0 $path =~ s!([^a-zA-Z0-9_.~-])!uc sprintf "%%%02x", ord($1)!eg;
1087 0 push ( @paths, $path );
1088 }
1089 0 $filename = join( $separator, @paths );
1090 0 return $filename;
1091 }
1092  
1093 0 ▶sub _basename {
Subroutine _basename: not called CC=12 SCAR=50.5
1094 0 my ( $filename, $separator, $want ) = @_;
1095 0 ▶ if (! $separator ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($separator) 0 0 0
1096 0 ▶ $separator = $^O eq 'MSWin32' ? '\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
1097 }
1098 0 ▶ $want = 'basename' unless $want;
Branch: 1 branch
BranchTrueFalseTotal
unless $want 0 0 0
1099 0 my $basename;
1100 0 ▶ if ( ( ( $^O ne 'MSWin32' ) && ( $separator eq '/' ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($^O ne 'MSWin32' and $separator eq '/' or $^O eq 'MSWin32' and $separator eq '\\') { } 0 0 0
Condition0%0/9
$^O ne "MSWin32" and $separator eq "/" or $^O eq "MSWin32" and $separator eq "\\"
l!l&&r!l&&!r
000
$^O ne "MSWin32" and $separator eq "/"
!ll&&!rl&&r
000
$^O eq "MSWin32" and $separator eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/4
$^O ne "MSWin32" and $separator eq "/" or $^O eq "MSWin32" and $separator eq "\\"
$^O ne "MSWin32" $separator eq "/" $^O eq "MSWin32" $separator eq "\\"
Truth table0%0/7
A and B or C and D
A= $^O ne "MSWin32"B= $separator eq "/"C= $^O eq "MSWin32"D= $separator eq "\\"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1101 ( ( $^O eq 'MSWin32' ) && ( $separator eq '\\' ) ) ) {
1102 0 ▶ if ( $want eq 'dirname' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($want eq 'dirname') { } 0 0 0
elsif ($want eq 'basename') { } 0 0 0
1103 0 $basename = File::Basename::dirname( $filename );
1104 } elsif ( $want eq 'basename' ) {
1105 0 $basename = File::Basename::basename( $filename );
1106 }
1107 } else {
1108 0 my $q = quotemeta( $separator );
1109 0 $filename =~ s/$q$//;
1110 0 my @fileparse = split( /$q/, $filename );
1111 0 ▶ if ( $want eq 'dirname' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want eq 'dirname') { } 0 0 0
1112 0 pop @fileparse;
1113 0 $basename = join( $separator, @fileparse );
1114 0 ▶ if (! $basename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($basename) 0 0 0
1115 0 $basename = '.';
1116 }
1117 } else {
1118 0 $basename = pop @fileparse;
1119 }
1120 }
1121 0 return $basename;
1122 }
1123  
1124 2 1;
1125  
1126 __END__
↑ Summary StorageClient.pm »