SDK/Storage/Tables/Serializer.pm

filter: Statementstmt 99.5% 221 / 222 Branchbran 68.2% 86 / 126 Conditioncond 44.7% 47 / 105 MC/DCmcdc 12.0% 7 / 58 Subroutinesub 100% 38 / 38 Podpod 0.0% 0 / 8 totaltotal 71.6% 399 / 557 CC 113 SCAR 28.0
CC
113
Cov
78%
parse_transaction_response
39.1
_entity_from_document
26.1
_batch_error
24.6
CRAP 16.5
« SDK/AppConfiguration/ConfigurationSetting.pm ↑ Summary SDK/Storage/Queues/ConnectionString.pm »
1 6 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 6 class Azure::SDK::Storage::Tables::Serializer {
6 6 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶ use Digest::SHA qw(sha256_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶ use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶ use MIME::Base64 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶ use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶ use Azure::SDK::Storage::Tables::Entity;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶ use Azure::SDK::Storage::Tables::EntityContinuation;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶ use Azure::SDK::Storage::Tables::EntityPage;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use Azure::SDK::Storage::Tables::EntityProperty;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use Azure::SDK::Storage::Tables::TableItem;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use Azure::SDK::Storage::Tables::TablePage;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use Azure::SDK::Storage::Tables::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use Azure::SDK::Storage::Tables::TransactionError;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use Azure::SDK::Storage::Tables::TransactionResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use Azure::SDK::Storage::Tables::TransactionResultItem;
Subroutine BEGIN: called CC=1 SCAR=0.0
23
24 6 ▶ use constant DEFAULT_MAX_BYTES => 8 * 1024 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶ use constant MAX_ENTITY_BODY_BYTES => 1024 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶ use constant MAX_TRANSACTION_BYTES => 4 * 1024 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
27
28 6 field $max_bytes :param :reader = DEFAULT_MAX_BYTES;
29 6 field $json = undef;
30 6 field $boundary_sequence = 0;
31
32 25 ▶ ADJUST {
Subroutine __ANON__: called CC=5 SCAR=21.9
33 25 ▶ croak 'Azure::SDK::Storage::Tables::Serializer max_bytes must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_bytes and not ref $max_bytes and $max_bytes =~ /\A[0-9]+\z/u and $max_bytes > 0 0 25 25
Condition33%3/9
defined $max_bytes and not ref $max_bytes and $max_bytes =~ /\A[0-9]+\z/u and $max_bytes > 0
!ll&&!rl&&r
0025
defined $max_bytes and not ref $max_bytes and $max_bytes =~ /\A[0-9]+\z/u
!ll&&!rl&&r
0025
defined $max_bytes and not ref $max_bytes
!ll&&!rl&&r
0025
MC/DC0%0/4
defined $max_bytes and not ref $max_bytes and $max_bytes =~ /\A[0-9]+\z/u and $max_bytes > 0
defined $max_bytes not ref $max_bytes $max_bytes =~ /\A[0-9]+\z/u $max_bytes > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $max_bytesB= not ref $max_bytesC= $max_bytes =~ /\A[0-9]+\z/uD= $max_bytes > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
34 unless defined $max_bytes
35 && !ref $max_bytes
36 && $max_bytes =~ /\A[0-9]+\z/
37 && $max_bytes > 0;
38 25 $json = JSON::PP->new->utf8->canonical;
39 }
40
41 6 ▶ method serialize_table ($table_name) {
Subroutine serialize_table: called CC=4 SCAR=17.9
Pod undocumented
42 6 ▶ croak 'Table name is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table_name and not ref $table_name and length $table_name 0 6 6
Condition33%2/6
defined $table_name and not ref $table_name and length $table_name
!ll&&!rl&&r
006
defined $table_name and not ref $table_name
!ll&&!rl&&r
006
MC/DC0%0/3
defined $table_name and not ref $table_name and length $table_name
defined $table_name not ref $table_name length $table_name
Truth table25%1/4
A and not(B) and C
A= defined $table_nameB= not ref $table_nameC= length $table_name
ABCresult
0XX0
10X0
1100
1111
43 unless defined $table_name && !ref $table_name && length $table_name;
44 6 return $json->encode({ TableName => $table_name });
45 }
46
47 13 ▶ method serialize_entity ($entity) {
Subroutine serialize_entity: called CC=7 SCAR=19.9
Pod undocumented
48 13 ▶ croak 'Table entity serialization requires an Entity'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($entity) and $entity->isa("Azure::SDK::Storage::Tables::Entity") 0 13 13
Condition33%1/3
builtin::blessed($entity) and $entity->isa("Azure::SDK::Storage::Tables::Entity")
!ll&&!rl&&r
0013
MC/DC0%0/2
builtin::blessed($entity) and $entity->isa("Azure::SDK::Storage::Tables::Entity")
builtin::blessed($entity) $entity->isa("Azure::SDK::Storage::Tables::Entity")
Truth table33%1/3
A and B
A= builtin::blessed($entity)B= $entity->isa("Azure::SDK::Storage::Tables::Entity")
ABresult
0X0
100
111
49 unless blessed($entity)
50 && $entity->isa('Azure::SDK::Storage::Tables::Entity');
51
52 13 my %document = (
53 PartitionKey => $entity->partition_key,
54 RowKey => $entity->row_key,
55 );
56 13 for my $name (keys $entity->properties->%*) {
57 94 ▶ next unless defined $entity->properties->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entity->properties->{$name} 1 93 94
58 my $property = Azure::SDK::Storage::Tables::EntityProperty->new(
59 type => $entity->property_type($name),
60 93 value => $entity->properties->{$name},
61 );
62 93 $document{$name} = $property->json_value;
63 93 ▶ $document{"$name\@odata.type"} = $property->type
Branch: 1 branch
BranchTrueFalseTotal
unless $property->type eq "Edm.String" 10 83 93
64 unless $property->type eq 'Edm.String';
65 }
66
67 13 my $body = $json->encode(\%document);
68 13 ▶ croak 'Table entity JSON body exceeds 1 MiB'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($body) > 1048576 0 13 13
69 if bytes::length($body) > MAX_ENTITY_BODY_BYTES;
70 13 return $body;
71 }
72
73 4 ▶ method serialize_transaction ($uri, $table, $transaction) {
Subroutine serialize_transaction: called CC=15 SCAR=27.2
Pod undocumented
74 4 ▶ croak 'Table transaction serialization requires a Transaction'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Azure::SDK::Storage::Tables::Transaction") 0 4 4
Condition33%1/3
builtin::blessed($transaction) and $transaction->isa("Azure::SDK::Storage::Tables::Transaction")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($transaction) and $transaction->isa("Azure::SDK::Storage::Tables::Transaction")
builtin::blessed($transaction) $transaction->isa("Azure::SDK::Storage::Tables::Transaction")
Truth table33%1/3
A and B
A= builtin::blessed($transaction)B= $transaction->isa("Azure::SDK::Storage::Tables::Transaction")
ABresult
0X0
100
111
75 unless blessed($transaction)
76 && $transaction->isa('Azure::SDK::Storage::Tables::Transaction');
77 4 ▶ croak 'Table transaction must contain at least one operation'
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->count 1 3 4
78 unless $transaction->count;
79 3 $uri->validate_table_name($table);
80
81 3 my $batch_boundary = $self->_boundary('batch');
82 3 my $change_boundary = $self->_boundary('changeset');
83 3 my @lines = (
84 "--$batch_boundary",
85 "Content-Type: multipart/mixed; boundary=$change_boundary",
86 '',
87 );
88
89 3 my $content_id = 0;
90 3 for my $operation ($transaction->operations->@*) {
91 10 $content_id++;
92 10 my $entity = $operation->entity;
93 10 my ($method, $target, $body);
94 10 ▶ if ($operation->action eq 'insert') {
Branch: 1 branch
BranchTrueFalseTotal
if ($operation->action eq 'insert') { } 8 2 10
95 8 $method = 'POST';
96 8 $target = $uri->for_insert($table)->{url};
97 8 $body = $self->serialize_entity($entity);
98 }
99 else {
100 2 ▶ $method = $operation->action eq 'replace'
Branch: 2 branches
BranchTrueFalseTotal
$operation->action eq 'replace' || $operation->action eq 'insert_or_replace' ? : 1 1 2
$operation->action eq 'delete' ? : 1 0 1
Condition66%2/3
$operation->action eq "replace" or $operation->action eq "insert_or_replace"
l!l&&r!l&&!r
101
MC/DC50%1/2
$operation->action eq "replace" or $operation->action eq "insert_or_replace"
$operation->action eq "replace" $operation->action eq "insert_or_replace"
Truth table66%2/3
A or B
A= $operation->action eq "replace"B= $operation->action eq "insert_or_replace"
ABresult
1X1
011
000
101 || $operation->action eq 'insert_or_replace'
102 ? 'PUT'
103 : $operation->action eq 'delete' ? 'DELETE' : 'MERGE';
104 $target = $uri->for_entity(
105 $table,
106 $entity->partition_key,
107 $entity->row_key,
108 2 )->{url};
109 2 ▶ $body = $self->serialize_entity($entity)
Branch: 1 branch
BranchTrueFalseTotal
unless $operation->action eq "delete" 1 1 2
110 unless $operation->action eq 'delete';
111 }
112
113 10 push @lines,
114 "--$change_boundary",
115 'Content-Type: application/http',
116 'Content-Transfer-Encoding: binary',
117 '',
118 "$method $target HTTP/1.1",
119 "Content-ID: $content_id",
120 'Accept: application/json;odata=nometadata',
121 'DataServiceVersion: 3.0;';
122 10 ▶ push @lines, 'If-Match: ' . $operation->if_match
Branch: 1 branch
BranchTrueFalseTotal
if defined $operation->if_match 2 8 10
123 if defined $operation->if_match;
124 10 ▶ if (defined $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) 9 1 10
125 9 push @lines,
126 'Content-Type: application/json',
127 'Content-Length: ' . bytes::length($body);
128 9 ▶ push @lines, 'Prefer: return-no-content'
Branch: 1 branch
BranchTrueFalseTotal
if $operation->action eq "insert" 8 1 9
129 if $operation->action eq 'insert';
130 }
131 10 ▶ push @lines, '', (defined $body ? $body : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 9 1 10
132 }
133
134 3 push @lines,
135 "--$change_boundary--",
136 "--$batch_boundary--",
137 '';
138 3 my $payload = join "\r\n", @lines;
139 3 ▶ croak 'Table transaction payload exceeds 4 MiB'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($payload) > 4194304 1 2 3
140 if bytes::length($payload) > MAX_TRANSACTION_BYTES;
141 2 return ($payload, $batch_boundary);
142 }
143
144 4 ▶ method parse_transaction_response ($body, $content_type, $expected_count) {
Subroutine parse_transaction_response: called CC=25 SCAR=36.7
Pod undocumented
145 4 ▶ croak 'Table transaction response body is empty'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body and length $body 0 4 4
Condition33%1/3
defined $body and length $body
!ll&&!rl&&r
004
MC/DC0%0/2
defined $body and length $body
defined $body length $body
Truth table33%1/3
A and B
A= defined $bodyB= length $body
ABresult
0X0
100
111
146 unless defined $body && length $body;
147 4 ▶ croak 'Table transaction response body exceeds ' . $max_bytes . ' bytes'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($body) > $max_bytes 0 4 4
148 if bytes::length($body) > $max_bytes;
149 4 ▶ croak 'Table transaction expected result count must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expected_count and not ref $expected_count and $expected_count =~ /\A[0-9]+\z/u and $expected_count > 0 0 4 4
Condition33%3/9
defined $expected_count and not ref $expected_count and $expected_count =~ /\A[0-9]+\z/u and $expected_count > 0
!ll&&!rl&&r
004
defined $expected_count and not ref $expected_count and $expected_count =~ /\A[0-9]+\z/u
!ll&&!rl&&r
004
defined $expected_count and not ref $expected_count
!ll&&!rl&&r
004
MC/DC0%0/4
defined $expected_count and not ref $expected_count and $expected_count =~ /\A[0-9]+\z/u and $expected_count > 0
defined $expected_count not ref $expected_count $expected_count =~ /\A[0-9]+\z/u $expected_count > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $expected_countB= not ref $expected_countC= $expected_count =~ /\A[0-9]+\z/uD= $expected_count > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
150 unless defined $expected_count
151 && !ref($expected_count)
152 && $expected_count =~ /\A[0-9]+\z/
153 && $expected_count > 0;
154
155 4 my $batch_boundary = _multipart_boundary(
156 $content_type,
157 'Table transaction response Content-Type',
158 );
159 4 ▶ croak 'Table transaction response does not contain its batch boundary'
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ /(?:\A|\r?\n)--\Q$batch_boundary\E(?:--)?(?:\r?\n|\z)/u 0 4 4
160 unless $body =~ /(?:\A|\r?\n)--\Q$batch_boundary\E(?:--)?(?:\r?\n|\z)/;
161
162 4 my ($nested_content_type) = $body =~
163 /(?:\A|\r?\n)Content-Type:[ \t]*([^\r\n]*multipart\/mixed[^\r\n]*)/i;
164 4 my $change_boundary = _multipart_boundary(
165 $nested_content_type,
166 'Table transaction changeset Content-Type',
167 );
168 4 my @segments = split(
169 /(?:\A|\r?\n)--\Q$change_boundary\E(?:--)?[ \t]*(?:\r?\n|\z)/,
170 $body,
171 );
172
173 4 my @items;
174 4 for my $segment (@segments) {
175 13 ▶ next unless $segment =~ /(?:\A|\r?\n)HTTP\/1\.[01][ \t]+([0-9]{3})[^\r\n]*\r?\n/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $segment =~ m[(?:\A|\r?\n)HTTP/1\.[01][ \t]+([0-9]{3})[^\r\n]*\r?\n]su 6 7 13
176 7 my $status = 0 + $1;
177 7 my $response_start = $+[0];
178 7 my $response = substr($segment, $response_start);
179 7 my ($header_block, $part_body) = split /\r?\n\r?\n/, $response, 2;
180 7 ▶ croak 'Table transaction inner response has malformed headers'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $header_block 0 7 7
181 unless defined $header_block;
182 7 my %headers;
183 7 for my $line (split /\r?\n/, $header_block) {
184 22 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 22 22
185 22 my ($name, $value) = $line =~ /\A([^:\s]+):[ \t]*(.*)\z/;
186 22 ▶ croak 'Table transaction inner response has a malformed header'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 22 22
187 unless defined $name;
188 22 $value =~ s/[ \t]+\z//;
189 22 $headers{lc $name} = $value;
190 }
191 7 ▶ $part_body =~ s/\r?\n\z// if defined $part_body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $part_body 4 3 7
192
193 7 ▶ if ($status < 200 || $status >= 300) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status < 200 or $status >= 300) 2 5 7
Condition66%2/3
$status < 200 or $status >= 300
l!l&&r!l&&!r
025
MC/DC50%1/2
$status < 200 or $status >= 300
$status < 200 $status >= 300
Truth table66%2/3
A or B
A= $status < 200B= $status >= 300
ABresult
1X1
011
000
194 2 my ($code, $message) = _batch_error($json, $part_body);
195 2 ▶ $message //= "Table transaction operation failed with HTTP $status";
Condition50%1/2
$message //= "Table transaction operation failed with HTTP $status"
l!l
20
MC/DC0%0/1
$message //= "Table transaction operation failed with HTTP $status"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
196 2 my $operation_index;
197 2 ▶ $operation_index = 0 + $1 if $message =~ /\A([0-9]+):/;
Branch: 1 branch
BranchTrueFalseTotal
if $message =~ /\A([0-9]+):/u 2 0 2
198 $operation_index //= $headers{'content-id'} - 1
199 if defined $headers{'content-id'}
200 2 ▶ && $headers{'content-id'} =~ /\A[1-9][0-9]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $headers{"content-id"} and $headers{"content-id"} =~ /\A[1-9][0-9]*\z/u 2 0 2
Condition40%2/5
defined $headers{"content-id"} and $headers{"content-id"} =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
002
$operation_index //= $headers{"content-id"} - 1
l!l
20
MC/DC0%0/2
defined $headers{"content-id"} and $headers{"content-id"} =~ /\A[1-9][0-9]*\z/u
defined $headers{"content-id"} $headers{"content-id"} =~ /\A[1-9][0-9]*\z/u
MC/DC0%0/1
$operation_index //= $headers{"content-id"} - 1
$operation_index
Truth table33%1/3
A and B
A= defined $headers{"content-id"}B= $headers{"content-id"} =~ /\A[1-9][0-9]*\z/u
ABresult
0X0
100
111
Truth table50%1/2
A
A= $operation_index
Aresult
11
00
201 2 ▶ $operation_index //= 0;
Condition50%1/2
$operation_index //= 0
l!l
20
MC/DC0%0/1
$operation_index //= 0
$operation_index
Truth table50%1/2
A
A= $operation_index
Aresult
11
00
202 2 Azure::SDK::Storage::Tables::TransactionError->new(
203 message => $message,
204 status => $status,
205 code => $code,
206 body => $part_body,
207 operation_index => $operation_index,
208 )->throw;
209 }
210
211 push @items, Azure::SDK::Storage::Tables::TransactionResultItem->new(
212 status => $status,
213 content_id => $headers{'content-id'},
214 etag => $headers{etag},
215 5 );
216 }
217
218 2 ▶ croak "Table transaction response returned " . scalar(@items)
Branch: 1 branch
BranchTrueFalseTotal
unless @items == $expected_count 0 2 2
219 . " results; expected $expected_count"
220 unless @items == $expected_count;
221 2 return Azure::SDK::Storage::Tables::TransactionResult->new(items => \@items);
222 }
223
224 6 ▶ method _boundary ($prefix) {
Subroutine _boundary: called CC=1 SCAR=0.0
225 6 my $digest = sha256_hex(join ':', $$, time, ++$boundary_sequence, rand());
226 6 return $prefix . '_' . substr($digest, 0, 32);
227 }
228
229 2 ▶ method decode_json ($body) {
Subroutine decode_json: called CC=1 SCAR=0.0
Pod undocumented
230 2 return $self->_decode($body);
231 }
232
233 13 ▶ method parse_table_list ( $body, $next_table_name = undef ) {
Subroutine parse_table_list: called CC=9 SCAR=22.0
Pod undocumented
234 13 my $document = $self->_decode($body);
235 11 ▶ croak 'Table listing response must be a JSON object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "HASH" 1 10 11
236 unless ref $document eq 'HASH';
237 croak 'Table listing response must contain a value array'
238 10 ▶ unless ref($document->{value}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document->{"value"} eq "ARRAY" 2 8 10
239
240 8 my @items;
241 8 for my $entry ($document->{value}->@*) {
242 8 ▶ croak 'Table listing table item must be a JSON object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry eq "HASH" 1 7 8
243 unless ref $entry eq 'HASH';
244 croak 'Table listing table item is missing TableName'
245 unless defined $entry->{TableName}
246 && !ref $entry->{TableName}
247 7 ▶ && length $entry->{TableName};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->{"TableName"} and not ref $entry->{"TableName"} and length $entry->{"TableName"} 1 6 7
Condition66%4/6
defined $entry->{"TableName"} and not ref $entry->{"TableName"} and length $entry->{"TableName"}
!ll&&!rl&&r
106
defined $entry->{"TableName"} and not ref $entry->{"TableName"}
!ll&&!rl&&r
106
MC/DC33%1/3
defined $entry->{"TableName"} and not ref $entry->{"TableName"} and length $entry->{"TableName"}
defined $entry->{"TableName"} not ref $entry->{"TableName"} length $entry->{"TableName"}
Truth table50%2/4
A and not(B) and C
A= defined $entry->{"TableName"}B= not ref $entry->{"TableName"}C= length $entry->{"TableName"}
ABCresult
0XX0
10X0
1100
1111
248 push @items, Azure::SDK::Storage::Tables::TableItem->new(
249 name => $entry->{TableName},
250 6 );
251 }
252
253 6 return Azure::SDK::Storage::Tables::TablePage->new(
254 items => \@items,
255 continuation_token => $next_table_name,
256 );
257 }
258
259 2 ▶ method parse_entity ( $body, $header_etag = undef ) {
Subroutine parse_entity: called CC=3 SCAR=11.1
Pod undocumented
260 2 my $document = $self->_decode($body);
261 2 ▶ croak 'Table entity response must be a JSON object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "HASH" 0 2 2
262 unless ref $document eq 'HASH';
263 2 return $self->_entity_from_document($document, $header_etag);
264 }
265
266 2 ▶ method parse_entity_list (
Subroutine parse_entity_list: called CC=7 SCAR=19.9
Pod undocumented
267 $body,
268 2 $next_partition_key = undef,
269 2 $next_row_key = undef,
270 ) {
271 2 my $document = $self->_decode($body);
272 2 ▶ croak 'Table entity listing response must be a JSON object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "HASH" 0 2 2
273 unless ref $document eq 'HASH';
274 croak 'Table entity listing response must contain a value array'
275 2 ▶ unless ref($document->{value}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document->{"value"} eq "ARRAY" 0 2 2
276
277 2 my @items;
278 2 for my $entry ($document->{value}->@*) {
279 2 ▶ croak 'Table entity listing item must be a JSON object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry eq "HASH" 0 2 2
280 unless ref $entry eq 'HASH';
281 2 push @items, $self->_entity_from_document($entry);
282 }
283
284 2 return Azure::SDK::Storage::Tables::EntityPage->new(
285 items => \@items,
286 continuation_token => Azure::SDK::Storage::Tables::EntityContinuation->encode(
287 $next_partition_key,
288 $next_row_key,
289 ),
290 next_partition_key => $next_partition_key,
291 next_row_key => $next_row_key,
292 );
293 }
294
295 4 ▶ method _entity_from_document ( $document, $header_etag = undef ) {
Subroutine _entity_from_document: called CC=21 SCAR=32.6
296 4 for my $required (qw(PartitionKey RowKey)) {
297 croak "Table entity response is missing $required"
298 unless defined $document->{$required}
299 8 ▶ && !ref $document->{$required};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $document->{$required} and not ref $document->{$required} 0 8 8
Condition33%1/3
defined $document->{$required} and not ref $document->{$required}
!ll&&!rl&&r
008
MC/DC0%0/2
defined $document->{$required} and not ref $document->{$required}
defined $document->{$required} not ref $document->{$required}
Truth table33%1/3
A and not(B)
A= defined $document->{$required}B= not ref $document->{$required}
ABresult
0X0
100
111
300 }
301
302 4 my (%properties, %types);
303 4 for my $name (keys $document->%*) {
304 27 ▶ next if $name eq 'PartitionKey'
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "PartitionKey" or $name eq "RowKey" or $name eq "Timestamp" or $name =~ /\A(?:odata\.|\@odata\.)/u 16 11 27
Condition100%9/9
$name eq "PartitionKey" or $name eq "RowKey" or $name eq "Timestamp" or $name =~ /\A(?:odata\.|\@odata\.)/u
l!l&&r!l&&!r
12411
$name eq "PartitionKey" or $name eq "RowKey" or $name eq "Timestamp"
l!l&&r!l&&!r
8415
$name eq "PartitionKey" or $name eq "RowKey"
l!l&&r!l&&!r
4419
MC/DC100%4/4
$name eq "PartitionKey" or $name eq "RowKey" or $name eq "Timestamp" or $name =~ /\A(?:odata\.|\@odata\.)/u
$name eq "PartitionKey" $name eq "RowKey" $name eq "Timestamp" $name =~ /\A(?:odata\.|\@odata\.)/u
Truth table100%5/5
A or B or C or D
A= $name eq "PartitionKey"B= $name eq "RowKey"C= $name eq "Timestamp"D= $name =~ /\A(?:odata\.|\@odata\.)/u
ABCDresult
1XXX1
01XX1
001X1
00011
00000
305 || $name eq 'RowKey'
306 || $name eq 'Timestamp'
307 || $name =~ /\A(?:odata\.|\@odata\.)/;
308 11 ▶ next if $name =~ /\@odata\.type\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\@odata\.type\z/u 4 7 11
309 7 Azure::SDK::Storage::Tables::Entity->validate_property_name($name);
310 7 ▶ next unless defined $document->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $document->{$name} 0 7 7
311
312 my $type = $document->{"$name\@odata.type"}
313 7 ▶ // _infer_type($json, $document->{$name});
Condition66%2/3
$$document{"$name\@odata.type"} // _infer_type($json, $document->{$name})
l!l&&r!l&&!r
430
MC/DC0%0/2
$$document{"$name\@odata.type"} // _infer_type($json, $document->{$name})
$$document{"$name\@odata.type"} _infer_type($json, $document->{$name})
Truth table66%2/3
A // B
A= $$document{"$name\@odata.type"}B= _infer_type($json, $document->{$name})
ABresult
1X1
011
000
314 7 my $value = $document->{$name};
315 7 ▶ if ($type eq 'Edm.Binary') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'Edm.Binary') { } 1 6 7
elsif ($type eq 'Edm.Boolean') { } 1 5 6
316 1 ▶ croak "Table entity property '$name' contains invalid base64"
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $value and $value =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u 0 1 1
Condition33%1/3
not ref $value and $value =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
!ll&&!rl&&r
001
MC/DC0%0/2
not ref $value and $value =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
not ref $value $value =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
Truth table33%1/3
not(A) and B
A= not ref $valueB= $value =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
ABresult
0X0
100
111
317 unless !ref($value)
318 && $value =~ /\A(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?\z/;
319 1 $value = decode_base64($value);
320 }
321 elsif ($type eq 'Edm.Boolean') {
322 1 ▶ croak "Table entity property '$name' must be a JSON boolean"
Branch: 1 branch
BranchTrueFalseTotal
unless JSON::PP::is_bool($value) 0 1 1
323 unless JSON::PP::is_bool($value);
324 1 ▶ $value = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 0 1
325 }
326
327 7 my $property = Azure::SDK::Storage::Tables::EntityProperty->new(
328 type => $type,
329 value => $value,
330 );
331 7 $properties{$name} = $property->value;
332 7 $types{$name} = $property->type;
333 }
334
335 return Azure::SDK::Storage::Tables::Entity->new(
336 partition_key => $document->{PartitionKey},
337 row_key => $document->{RowKey},
338 timestamp => $document->{Timestamp},
339 etag => $document->{'odata.etag'}
340 4 ▶ // $document->{'@odata.etag'}
Condition33%2/6
($document->{"odata.etag"} // $document->{"\@odata.etag"}) // $header_etag
l!l&&r!l&&!r
400
$document->{"odata.etag"} // $document->{"\@odata.etag"}
l!l&&r!l&&!r
400
MC/DC0%0/3
($document->{"odata.etag"} // $document->{"\@odata.etag"}) // $header_etag
$document->{"odata.etag"} $document->{"\@odata.etag"} $header_etag
Truth table25%1/4
A // B // C
A= $document->{"odata.etag"}B= $document->{"\@odata.etag"}C= $header_etag
ABCresult
1XX1
01X1
0011
0000
341 // $header_etag,
342 properties => \%properties,
343 property_types => \%types,
344 );
345 }
346
347 19 ▶ method _decode ($body) {
Subroutine _decode: called CC=5 SCAR=16.5
348 19 ▶ croak 'Table response body is empty'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body and length $body 0 19 19
Condition33%1/3
defined $body and length $body
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $body and length $body
defined $body length $body
Truth table33%1/3
A and B
A= defined $bodyB= length $body
ABresult
0X0
100
111
349 unless defined $body && length $body;
350 19 ▶ croak 'Table response body exceeds ' . $max_bytes . ' bytes'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($body) > $max_bytes 1 18 19
351 if bytes::length($body) > $max_bytes;
352
353 18 my $document = eval { $json->decode($body) };
354 18 ▶ croak 'Table response body is not valid JSON'
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 17 18
355 if $@;
356 17 return $document;
357 }
358
359 3 ▶ sub _infer_type ( $coder, $value ) {
Subroutine _infer_type: called CC=5 SCAR=20.1
360 3 ▶ return 'Edm.Boolean' if JSON::PP::is_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
if JSON::PP::is_bool($value) 0 3 3
361 3 ▶ return 'Edm.String' if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 3 3
362 3 my $encoded = $coder->encode([$value]);
363 3 ▶ return 'Edm.String' if $encoded =~ /\A\["/;
Branch: 1 branch
BranchTrueFalseTotal
if $encoded =~ /\A\["/u 3 0 3
364 0 ▶ return $encoded =~ /[.eE]/ ? 'Edm.Double' : 'Edm.Int32';
Branch: 1 branch
BranchTrueFalseTotal
$encoded =~ /[.eE]/u ? : 0 0 0
365 }
366
367 8 ▶ sub _multipart_boundary ($content_type, $label) {
Subroutine _multipart_boundary: called CC=7 SCAR=24.4
368 8 ▶ croak "$label is missing"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content_type and not ref $content_type 0 8 8
Condition33%1/3
defined $content_type and not ref $content_type
!ll&&!rl&&r
008
MC/DC0%0/2
defined $content_type and not ref $content_type
defined $content_type not ref $content_type
Truth table33%1/3
A and not(B)
A= defined $content_typeB= not ref $content_type
ABresult
0X0
100
111
369 unless defined $content_type && !ref($content_type);
370 8 my ($quoted, $bare) = $content_type =~
371 /(?:\A|;)[ \t]*boundary[ \t]*=[ \t]*(?:"([^"]+)"|([^;\s]+))/i;
372 8 ▶ my $boundary = defined $quoted ? $quoted : $bare;
Branch: 1 branch
BranchTrueFalseTotal
defined $quoted ? : 0 8 8
373 8 ▶ croak "$label has no valid boundary"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $boundary and length $boundary <= 70 and $boundary =~ m[\A[A-Za-z0-9'()+_,./:=?-]+\z]u 0 8 8
Condition33%2/6
defined $boundary and length $boundary <= 70 and $boundary =~ m[\A[A-Za-z0-9'()+_,./:=?-]+\z]u
!ll&&!rl&&r
008
defined $boundary and length $boundary <= 70
!ll&&!rl&&r
008
MC/DC0%0/3
defined $boundary and length $boundary <= 70 and $boundary =~ m[\A[A-Za-z0-9'()+_,./:=?-]+\z]u
defined $boundary length $boundary <= 70 $boundary =~ m[\A[A-Za-z0-9'()+_,./:=?-]+\z]u
Truth table25%1/4
A and B and C
A= defined $boundaryB= length $boundary <= 70C= $boundary =~ m[\A[A-Za-z0-9'()+_,./:=?-]+\z]u
ABCresult
0XX0
10X0
1100
1111
374 unless defined $boundary
375 && length($boundary) <= 70
376 && $boundary =~ /\A[A-Za-z0-9'()+_,.\/:=?-]+\z/;
377 8 return $boundary;
378 }
379
380 2 ▶ sub _batch_error ($coder, $body) {
Subroutine _batch_error: called CC=12 SCAR=32.0
381 2 ▶ return unless defined $body && length $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body and length $body 0 2 2
Condition33%1/3
defined $body and length $body
!ll&&!rl&&r
002
MC/DC0%0/2
defined $body and length $body
defined $body length $body
Truth table33%1/3
A and B
A= defined $bodyB= length $body
ABresult
0X0
100
111
382 2 my $document = eval { $coder->decode($body) };
383 2 ▶ return unless ref $document eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "HASH" 0 2 2
384 2 ▶ my $error = $document->{'odata.error'} // $document->{error} // $document;
Condition33%2/6
($document->{"odata.error"} // $document->{"error"}) // $document
l!l&&r!l&&!r
200
$document->{"odata.error"} // $document->{"error"}
l!l&&r!l&&!r
200
MC/DC0%0/3
($document->{"odata.error"} // $document->{"error"}) // $document
$document->{"odata.error"} $document->{"error"} $document
Truth table25%1/4
A // B // C
A= $document->{"odata.error"}B= $document->{"error"}C= $document
ABCresult
1XX1
01X1
0011
0000
385 2 ▶ return unless ref $error eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $error eq "HASH" 0 2 2
386 2 my $message = $error->{message};
387 2 ▶ $message = $message->{value} if ref $message eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $message eq "HASH" 2 0 2
388 return (
389 defined $error->{code} && !ref $error->{code} ? $error->{code} : undef,
390 2 ▶ defined $message && !ref $message ? $message : undef,
Branch: 2 branches
BranchTrueFalseTotal
defined $error->{'code'} && !ref($error->{'code'}) ? : 2 0 2
defined $message && !ref($message) ? : 2 0 2
Condition33%2/6
defined $error->{"code"} and not ref $error->{"code"}
!ll&&!rl&&r
002
defined $message and not ref $message
!ll&&!rl&&r
002
MC/DC0%0/2
defined $error->{"code"} and not ref $error->{"code"}
defined $error->{"code"} not ref $error->{"code"}
MC/DC0%0/2
defined $message and not ref $message
defined $message not ref $message
Truth table33%1/3
A and not(B)
A= defined $error->{"code"}B= not ref $error->{"code"}
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= defined $messageB= not ref $message
ABresult
0X0
100
111
391 );
392 }
393 }
394
395 6 1;
396
397 __END__
« SDK/AppConfiguration/ConfigurationSetting.pm ↑ Summary SDK/Storage/Queues/ConnectionString.pm »