SDK/Storage/Tables/Uri.pm

filter: Statementstmt 100% 90 / 90 Branchbran 75.0% 30 / 40 Conditioncond 48.2% 14 / 29 MC/DCmcdc 17.6% 3 / 17 Subroutinesub 100% 21 / 21 Podpod 0.0% 0 / 9 totaltotal 76.7% 158 / 206 CC 37 SCAR 19.0
CC
37
Cov
84%
_normalize_endpoint
14.8
_validate_query
10.7
_validate_table_name
5.3
CRAP 6.7
« SDK/Storage/Blobs/Uri.pm ↑ Summary SDK/AppConfiguration/ConfigurationLabel.pm »
1 5 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 5 class Azure::SDK::Storage::Tables::Uri {
6 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶ use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 5 field $endpoint :param :reader = undef;
10 5 field $endpoint_path :reader = undef;
11
12 26 ▶ ADJUST {
Subroutine __ANON__: called CC=3 SCAR=13.1
13 26 ▶ croak 'Azure::SDK::Storage::Tables::Uri requires an endpoint'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endpoint and length $endpoint 0 26 26
Condition33%1/3
defined $endpoint and length $endpoint
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $endpoint and length $endpoint
defined $endpoint length $endpoint
Truth table33%1/3
A and B
A= defined $endpointB= length $endpoint
ABresult
0X0
100
111
14 unless defined $endpoint && length $endpoint;
15 26 ( $endpoint, $endpoint_path ) = _normalize_endpoint($endpoint);
16 }
17
18 19 ▶ sub from_connection_string ( $class, $connection ) {
Subroutine from_connection_string: called CC=1 SCAR=0.0
Pod undocumented
19 19 return $class->new(endpoint => $connection->table_endpoint);
20 }
21
22 27 ▶ sub normalize_endpoint ( $class, $value ) {
Subroutine normalize_endpoint: called CC=1 SCAR=0.0
Pod undocumented
23 27 return _normalize_endpoint($value);
24 }
25
26 10 ▶ method for_tables ( $query = {} ) {
Subroutine for_tables: called CC=2 SCAR=6.9
Pod undocumented
27 10 return $self->_build('Tables', $query);
28 }
29
30 2 ▶ method for_batch () {
Subroutine for_batch: called CC=1 SCAR=0.0
Pod undocumented
31 2 return $self->_build('$batch', {});
32 }
33
34 13 ▶ method validate_table_name ($table) {
Subroutine validate_table_name: called CC=1 SCAR=0.0
Pod undocumented
35 13 return _validate_table_name($table);
36 }
37
38 9 ▶ method for_table ( $table, $query = {} ) {
Subroutine for_table: called CC=2 SCAR=6.9
Pod undocumented
39 9 $table = _validate_table_name($table);
40 4 return $self->_build("Tables('$table')", $query);
41 }
42
43 5 ▶ method for_entities ( $table, $query = {} ) {
Subroutine for_entities: called CC=2 SCAR=6.9
Pod undocumented
44 5 $table = _validate_table_name($table);
45 5 return $self->_build("$table()", $query);
46 }
47
48 10 ▶ method for_insert ( $table, $query = {} ) {
Subroutine for_insert: called CC=2 SCAR=6.9
Pod undocumented
49 10 $table = _validate_table_name($table);
50 10 return $self->_build($table, $query);
51 }
52
53 17 ▶ method for_entity ( $table, $partition_key, $row_key, $query = {} ) {
Subroutine for_entity: called CC=2 SCAR=6.9
Pod undocumented
54 17 $table = _validate_table_name($table);
55 17 my $partition = _encode_key('PartitionKey', $partition_key);
56 12 my $row = _encode_key('RowKey', $row_key);
57 11 return $self->_build(
58 "$table(PartitionKey='$partition',RowKey='$row')",
59 $query,
60 );
61 }
62
63 42 ▶ method _build ( $path, $query ) {
Subroutine _build: called CC=2 SCAR=6.9
64 42 my %normalized = _validate_query($query);
65 40 my $suffix = '/' . $path;
66 40 my $url = $endpoint . $suffix;
67 40 ▶ if (%normalized) {
Branch: 1 branch
BranchTrueFalseTotal
if (%normalized) 8 32 40
68 $url .= '?' . join '&', map {
69 8 _encode_query($_) . '=' . _encode_query($normalized{$_})
70 } sort keys %normalized;
71 }
72
73 return {
74 40 url => $url,
75 canonical_path => $endpoint_path . $suffix,
76 };
77 }
78
79 29 ▶ sub _encode_key ( $label, $value ) {
Subroutine _encode_key: called CC=5 SCAR=16.3
80 29 ▶ croak "$label is required"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 0 29 29
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0029
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
81 unless defined $value && !ref $value;
82 29 ▶ croak "$label must not exceed 1024 characters"
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 1024 1 28 29
83 if length($value) > 1024;
84 28 ▶ croak "$label contains a character not permitted by Table Storage"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ m[[/\\#?\x00-\x1f\x7f-\x9f]]u 5 23 28
85 if $value =~ m{[/\\#?\x00-\x1f\x7f-\x9f]};
86
87 23 my $escaped = $value;
88 23 $escaped =~ s/'/''/g;
89 23 my $bytes = $escaped;
90 23 utf8::encode($bytes);
91 23 $bytes =~ s/([^A-Za-z0-9\-._~'])/sprintf('%%%02X', ord $1)/ge;
92 23 return $bytes;
93 }
94
95 40 ▶ sub _encode_query ($value) {
Subroutine _encode_query: called CC=1 SCAR=0.0
96 40 my $bytes = $value;
97 40 utf8::encode($bytes);
98 40 $bytes =~ s/([^A-Za-z0-9\-._~])/sprintf('%%%02X', ord $1)/ge;
99 40 return $bytes;
100 }
101
102 53 ▶ sub _normalize_endpoint ($value) {
Subroutine _normalize_endpoint: called CC=12 SCAR=27.0
103 53 ▶ croak 'Table endpoint is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 53 53
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
0053
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
104 unless defined $value && length $value;
105
106 53 my $uri = URI->new($value);
107 53 ▶ croak 'Table endpoint must be an absolute http or https URI'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u 0 53 53
Condition33%1/3
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
!ll&&!rl&&r
0053
MC/DC0%0/2
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
defined $uri->scheme $uri->scheme =~ /\Ahttps?\z/u
Truth table33%1/3
A and B
A= defined $uri->schemeB= $uri->scheme =~ /\Ahttps?\z/u
ABresult
0X0
100
111
108 unless defined $uri->scheme && $uri->scheme =~ /\Ahttps?\z/;
109 53 ▶ croak 'Table endpoint must include a host'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri->host and length $uri->host 0 53 53
Condition33%1/3
defined $uri->host and length $uri->host
!ll&&!rl&&r
0053
MC/DC0%0/2
defined $uri->host and length $uri->host
defined $uri->host length $uri->host
Truth table33%1/3
A and B
A= defined $uri->hostB= length $uri->host
ABresult
0X0
100
111
110 unless defined $uri->host && length $uri->host;
111 53 ▶ croak 'Table endpoint must not include userinfo'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->userinfo 2 51 53
112 if defined $uri->userinfo;
113 51 ▶ croak 'Table endpoint must not include a query string'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->query 1 50 51
114 if defined $uri->query;
115 50 ▶ croak 'Table endpoint must not include a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->fragment 1 49 50
116 if defined $uri->fragment;
117
118 49 ▶ my $path = $uri->path // '';
Condition50%1/2
$uri->path // ""
l!l
490
MC/DC0%0/1
$uri->path // ""
$uri->path
Truth table50%1/2
A
A= $uri->path
Aresult
11
00
119 49 $path =~ s{/+\z}{};
120 49 ▶ croak 'Table endpoint path must not contain relative segments'
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[(?:\A|/)\.\.?(?:/|\z)]u 1 48 49
121 if $path =~ m{(?:\A|/)\.\.?(?:/|\z)};
122
123 48 my $authority = $uri->scheme . '://' . $uri->authority;
124 48 return ( $authority . $path, $path );
125 }
126
127 54 ▶ sub _validate_table_name ($name) {
Subroutine _validate_table_name: called CC=5 SCAR=16.7
128 54 ▶ croak 'Table name must be 3-63 alphanumeric characters, start with a letter, '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and not ref $name and $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/u and lc $name ne "tables" 6 48 54
Condition66%6/9
defined $name and not ref $name and $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/u and lc $name ne "tables"
!ll&&!rl&&r
5148
defined $name and not ref $name and $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/u
!ll&&!rl&&r
0549
defined $name and not ref $name
!ll&&!rl&&r
0054
MC/DC50%2/4
defined $name and not ref $name and $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/u and lc $name ne "tables"
defined $name not ref $name $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/u lc $name ne "tables"
Truth table60%3/5
A and not(B) and C and D
A= defined $nameB= not ref $nameC= $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/uD= lc $name ne "tables"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
129 . 'and must not be the reserved name Tables'
130 unless defined $name
131 && !ref $name
132 && $name =~ /\A[A-Za-z][A-Za-z0-9]{2,62}\z/
133 && lc($name) ne 'tables';
134 48 return $name;
135 }
136
137 42 ▶ sub _validate_query ($query) {
Subroutine _validate_query: called CC=10 SCAR=23.7
138 42 ▶ return () unless defined $query;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query 0 42 42
139 42 ▶ croak 'Query parameters must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $query eq "HASH" 0 42 42
140 unless ref $query eq 'HASH';
141
142 42 my (%normalized, %seen);
143 42 for my $name (keys %{$query}) {
144 23 ▶ croak 'Query parameter names must be alphanumeric, "-", "_", ".", or start with "$"'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name =~ /\A\$?[A-Za-z0-9_.\-]+\z/u 1 22 23
Condition66%2/3
defined $name and $name =~ /\A\$?[A-Za-z0-9_.\-]+\z/u
!ll&&!rl&&r
0122
MC/DC50%1/2
defined $name and $name =~ /\A\$?[A-Za-z0-9_.\-]+\z/u
defined $name $name =~ /\A\$?[A-Za-z0-9_.\-]+\z/u
Truth table66%2/3
A and B
A= defined $nameB= $name =~ /\A\$?[A-Za-z0-9_.\-]+\z/u
ABresult
0X0
100
111
145 unless defined $name && $name =~ /\A\$?[A-Za-z0-9_.\-]+\z/;
146 22 my $collision_key = lc $name;
147 croak "Query parameter '$name' is repeated"
148 22 ▶ if $seen{$collision_key}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$collision_key}++ 1 21 22
149
150 21 my $value = $query->{$name};
151 21 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 21 21
152 21 ▶ croak "Query parameter '$name' must be a scalar"
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 21 21
153 if ref $value;
154 21 ▶ croak "Query parameter '$name' must not contain control characters"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x1f\x7f]/u 0 21 21
155 if $value =~ /[\x00-\x1f\x7f]/;
156 21 $normalized{$name} = "$value";
157 }
158 40 return %normalized;
159 }
160 }
161
162 5 1;
163
164 __END__
« SDK/Storage/Blobs/Uri.pm ↑ Summary SDK/AppConfiguration/ConfigurationLabel.pm »