SDK/Core.pm

filter: Statementstmt 99.0% 106 / 107 Branchbran 72.2% 39 / 54 Conditioncond 60.5% 43 / 71 MC/DCmcdc 32.5% 13 / 40 Subroutinesub 95.4% 21 / 22 Podpod 100% 5 / 5 totaltotal 75.9% 227 / 299 CC 53 SCAR 30.8
CC
53
Cov
81%
_raise_error
46.3
__ANON__
9.1
_parse_xml_error
8.4
CRAP 21.8
« SDK/AppConfiguration/Uri.pm ↑ Summary SDK/AppConfiguration/CreateSnapshotOperation.pm »
1 10 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 10 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 10 ▶use Azure::SDK::Core::ClientOptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Azure::SDK::Core::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Azure::SDK::Core::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Azure::SDK::Core::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use XML::LibXML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 10 class Azure::SDK::Core {
12 10 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15
16 10 ▶ use constant MAX_ERROR_ENVELOPE_BYTES => 16 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
17
18 10 field $endpoint :param :reader = undef;
19 10 field $options :param :reader = undef;
20 10 field $api_version :param = undef;
21 10 field $diagnostics_enabled :param = undef;
22 10 field $credential :param = undef;
23 10 field $transport :param = undef;
24 10 field $logger :param = undef;
25 10 field $max_response_bytes :param = undef;
26
27 10 field $pipeline = undef;
28
29 80 ▶ ADJUST {
Subroutine __ANON__: called CC=8 SCAR=22.1
30 80 ▶ return if defined $options;
Branch: 1 branch
BranchTrueFalseTotal
if defined $options 77 3 80
31
32 3 my %args;
33 3 ▶ $args{api_version} = $api_version if defined $api_version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $api_version 0 3 3
34 3 ▶ $args{diagnostics_enabled} = $diagnostics_enabled if defined $diagnostics_enabled;
Branch: 1 branch
BranchTrueFalseTotal
if defined $diagnostics_enabled 0 3 3
35 3 ▶ $args{credential} = $credential if defined $credential;
Branch: 1 branch
BranchTrueFalseTotal
if defined $credential 0 3 3
36 3 ▶ $args{transport} = $transport if defined $transport;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport 0 3 3
37 3 ▶ $args{logger} = $logger if defined $logger;
Branch: 1 branch
BranchTrueFalseTotal
if defined $logger 0 3 3
38 3 ▶ $args{max_response_bytes} = $max_response_bytes if defined $max_response_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max_response_bytes 0 3 3
39
40 3 $options = Azure::SDK::Core::ClientOptions->new(%args);
41 }
42
43 1 ▶ method api_version () {
Subroutine api_version: called CC=1 SCAR=0.0
Pod documented
44 1 return $options->api_version;
45 }
46
47 2 ▶ method diagnostics_enabled () {
Subroutine diagnostics_enabled: called CC=1 SCAR=0.0
Pod documented
48 2 return $options->diagnostics_enabled;
49 }
50
51 109 ▶ method pipeline () {
Subroutine pipeline: called CC=2 SCAR=7.1
Pod documented
52 109 ▶ $pipeline //= $options->build_pipeline;
Condition66%2/3
$pipeline //= $options->build_pipeline
l!l&&r!l&&!r
40690
MC/DC0%0/2
$pipeline //= $options->build_pipeline
$pipeline $options->build_pipeline
Truth table66%2/3
A //= B
A= $pipelineB= $options->build_pipeline
ABresult
1X1
011
000
53 109 return $pipeline;
54 }
55
56 110 ▶ method send ($request, $context = undef) {
Subroutine send: called CC=7 SCAR=20.1
Pod documented
57 110 ▶ croak 'Azure::SDK::Core->send requires an Azure::SDK::Core::Request'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request and builtin::blessed($request) and $request->isa("Azure::SDK::Core::Request") 1 109 110
Condition66%4/6
defined $request and builtin::blessed($request) and $request->isa("Azure::SDK::Core::Request")
!ll&&!rl&&r
10109
defined $request and builtin::blessed($request)
!ll&&!rl&&r
01109
MC/DC33%1/3
defined $request and builtin::blessed($request) and $request->isa("Azure::SDK::Core::Request")
defined $request builtin::blessed($request) $request->isa("Azure::SDK::Core::Request")
Truth table50%2/4
A and B and C
A= defined $requestB= builtin::blessed($request)C= $request->isa("Azure::SDK::Core::Request")
ABCresult
0XX0
10X0
1100
1111
58 unless defined $request
59 && Scalar::Util::blessed($request)
60 && $request->isa('Azure::SDK::Core::Request');
61
62 109 ▶ $context //= Azure::SDK::Core::Context->new;
Condition33%1/3
$context //= "Azure::SDK::Core::Context"->new
l!l&&r!l&&!r
01090
MC/DC0%0/2
$context //= "Azure::SDK::Core::Context"->new
$context "Azure::SDK::Core::Context"->new
Truth table33%1/3
A //= B
A= $contextB= "Azure::SDK::Core::Context"->new
ABresult
1X1
011
000
63 109 my $response = $self->pipeline->send($context, $request);
64
65 109 ▶ $self->_raise_error($response) unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 34 75 109
66
67 75 return $response;
68 }
69
70 # Parses the response body for an Azure REST error envelope and throws
71 # Azure::SDK::Core::Error. Called on any non-2xx pipeline result.
72 34 ▶ method _raise_error ($response) {
Subroutine _raise_error: called CC=30 SCAR=38.4
73 34 my ($code, $message);
74
75 34 my $parsed = eval { $response->decoded_json };
76 34 ▶ if (ref $parsed eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parsed eq "HASH") 5 29 34
77 5 ▶ my $err = $parsed->{error} // $parsed->{'odata.error'} // $parsed;
Condition83%5/6
($parsed->{"error"} // $parsed->{"odata.error"}) // $parsed
l!l&&r!l&&!r
410
$parsed->{"error"} // $parsed->{"odata.error"}
l!l&&r!l&&!r
221
MC/DC0%0/3
($parsed->{"error"} // $parsed->{"odata.error"}) // $parsed
$parsed->{"error"} $parsed->{"odata.error"} $parsed
Truth table75%3/4
A // B // C
A= $parsed->{"error"}B= $parsed->{"odata.error"}C= $parsed
ABCresult
1XX1
01X1
0011
0000
78 5 ▶ if (ref $err eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $err eq "HASH") 5 0 5
79 $code = $err->{code}
80 5 ▶ if defined $err->{code} && !ref $err->{code};
Branch: 1 branch
BranchTrueFalseTotal
if defined $err->{"code"} and not ref $err->{"code"} 3 2 5
Condition66%2/3
defined $err->{"code"} and not ref $err->{"code"}
!ll&&!rl&&r
203
MC/DC50%1/2
defined $err->{"code"} and not ref $err->{"code"}
defined $err->{"code"} not ref $err->{"code"}
Truth table66%2/3
A and not(B)
A= defined $err->{"code"}B= not ref $err->{"code"}
ABresult
0X0
100
111
81
82 5 my $error_message = $err->{message};
83 $error_message = $error_message->{value}
84 5 ▶ if ref $error_message eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $error_message eq "HASH" 2 3 5
85 5 ▶ $message = $error_message
Branch: 1 branch
BranchTrueFalseTotal
if defined $error_message and not ref $error_message 4 1 5
Condition66%2/3
defined $error_message and not ref $error_message
!ll&&!rl&&r
104
MC/DC50%1/2
defined $error_message and not ref $error_message
defined $error_message not ref $error_message
Truth table66%2/3
A and not(B)
A= defined $error_messageB= not ref $error_message
ABresult
0X0
100
111
86 if defined $error_message && !ref $error_message;
87
88 5 ▶ if (!defined $message) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message) 1 4 5
89 1 my $title = $err->{title};
90 1 ▶ $title = undef
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title and not ref $title and length $title 0 1 1
Condition33%2/6
defined $title and not ref $title and length $title
!ll&&!rl&&r
001
defined $title and not ref $title
!ll&&!rl&&r
001
MC/DC0%0/3
defined $title and not ref $title and length $title
defined $title not ref $title length $title
Truth table25%1/4
A and not(B) and C
A= defined $titleB= not ref $titleC= length $title
ABCresult
0XX0
10X0
1100
1111
91 unless defined $title && !ref $title && length $title;
92 1 my $detail = $err->{detail};
93 1 ▶ $detail = undef
Branch: 1 branch
BranchTrueFalseTotal
unless defined $detail and not ref $detail and length $detail 0 1 1
Condition33%2/6
defined $detail and not ref $detail and length $detail
!ll&&!rl&&r
001
defined $detail and not ref $detail
!ll&&!rl&&r
001
MC/DC0%0/3
defined $detail and not ref $detail and length $detail
defined $detail not ref $detail length $detail
Truth table25%1/4
A and not(B) and C
A= defined $detailB= not ref $detailC= length $detail
ABCresult
0XX0
10X0
1100
1111
94 unless defined $detail && !ref $detail && length $detail;
95 1 ▶ $message = defined $title && defined $detail && $title ne $detail
Branch: 1 branch
BranchTrueFalseTotal
defined $title && defined $detail && $title ne $detail ? : 1 0 1
Condition22%2/9
defined $title and defined $detail and $title ne $detail
!ll&&!rl&&r
001
defined $title and defined $detail
!ll&&!rl&&r
001
$detail // $title
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $title and defined $detail and $title ne $detail
defined $title defined $detail $title ne $detail
MC/DC0%0/2
$detail // $title
$detail $title
Truth table25%1/4
A and B and C
A= defined $titleB= defined $detailC= $title ne $detail
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A // B
A= $detailB= $title
ABresult
1X1
011
000
96 ? "$title: $detail"
97 : $detail // $title;
98 }
99
100 5 my $problem_type = $err->{type};
101 5 ▶ $code = $problem_type
Branch: 1 branch
BranchTrueFalseTotal
if not defined $code and defined $problem_type and not ref $problem_type and length $problem_type 1 4 5
Condition77%7/9
not defined $code and defined $problem_type and not ref $problem_type and length $problem_type
!ll&&!rl&&r
401
not defined $code and defined $problem_type and not ref $problem_type
!ll&&!rl&&r
401
not defined $code and defined $problem_type
!ll&&!rl&&r
311
MC/DC50%2/4
not defined $code and defined $problem_type and not ref $problem_type and length $problem_type
not defined $code defined $problem_type not ref $problem_type length $problem_type
Truth table60%3/5
not(A) and B and not(C) and D
A= not defined $codeB= defined $problem_typeC= not ref $problem_typeD= length $problem_type
ABCDresult
0XXX0
10XX0
110X0
11100
11111
102 if !defined $code
103 && defined $problem_type
104 && !ref $problem_type
105 && length $problem_type;
106 }
107 }
108
109 34 ▶ if (!defined $code || !defined $message) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code and defined $message) 30 4 34
Condition66%2/3
defined $code and defined $message
!ll&&!rl&&r
3004
MC/DC50%1/2
defined $code and defined $message
defined $code defined $message
Truth table66%2/3
A and B
A= defined $codeB= defined $message
ABresult
0X0
100
111
110 30 my ($xml_code, $xml_message) = _parse_xml_error($response->body);
111 30 ▶ $code //= $xml_code;
Condition66%2/3
$code //= $xml_code
l!l&&r!l&&!r
0246
MC/DC50%1/2
$code //= $xml_code
$code $xml_code
Truth table66%2/3
A //= B
A= $codeB= $xml_code
ABresult
1X1
011
000
112 30 ▶ $message //= $xml_message;
Condition100%3/3
$message //= $xml_message
l!l&&r!l&&!r
1245
MC/DC100%2/2
$message //= $xml_message
$message $xml_message
Truth table100%3/3
A //= B
A= $messageB= $xml_message
ABresult
1X1
011
000
113 }
114
115 34 ▶ $message //= 'HTTP ' . $response->status . ' error';
Condition100%2/2
$message //= 'HTTP ' . $response->status . ' error'
l!l
295
MC/DC100%1/1
$message //= 'HTTP ' . $response->status . ' error'
$message
Truth table100%2/2
A
A= $message
Aresult
11
00
116
117 34 Azure::SDK::Core::Error->new(
118 message => $message,
119 status => $response->status,
120 code => $code,
121 body => $response->body,
122 )->throw;
123 }
124
125 1 ▶ method as_hashref () {
Subroutine as_hashref: called CC=1 SCAR=0.0
Pod documented
126 return {
127 1 endpoint => $endpoint,
128 api_version => $options->api_version,
129 diagnostics_enabled => $options->diagnostics_enabled,
130 };
131 }
132
133 30 ▶ sub _parse_xml_error ($body) {
Subroutine _parse_xml_error: called CC=8 SCAR=21.2
134 30 ▶ return unless defined $body && $body =~ /<Error[\s>]/s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body and $body =~ /<Error[\s>]/su 5 25 30
Condition100%3/3
defined $body and $body =~ /<Error[\s>]/su
!ll&&!rl&&r
4125
MC/DC100%2/2
defined $body and $body =~ /<Error[\s>]/su
defined $body $body =~ /<Error[\s>]/su
Truth table100%3/3
A and B
A= defined $bodyB= $body =~ /<Error[\s>]/su
ABresult
0X0
100
111
135 25 ▶ return if bytes::length($body) > MAX_ERROR_ENVELOPE_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($body) > 16384 0 25 25
136
137 25 my $parser = XML::LibXML->new(
138 no_network => 1,
139 load_ext_dtd => 0,
140 expand_entities => 0,
141 huge => 0,
142 recover => 0,
143 no_blanks => 1,
144 );
145 0 ▶ $parser->set_option( ext_ent_handler => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
146 0 croak 'Refusing to resolve an external entity in an Azure error response';
147 25 } );
148
149 25 my $document = eval { $parser->load_xml( string => $body ) };
150 25 ▶ return unless defined $document;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $document 0 25 25
151 25 ▶ return if defined $document->internalSubset || defined $document->externalSubset;
Branch: 1 branch
BranchTrueFalseTotal
if defined $document->internalSubset or defined $document->externalSubset 1 24 25
Condition66%2/3
defined $document->internalSubset or defined $document->externalSubset
l!l&&r!l&&!r
1024
MC/DC50%1/2
defined $document->internalSubset or defined $document->externalSubset
defined $document->internalSubset defined $document->externalSubset
Truth table66%2/3
A or B
A= defined $document->internalSubsetB= defined $document->externalSubset
ABresult
1X1
011
000
152
153 24 my ($root) = $document->findnodes('/*[local-name()="Error"]');
154 24 ▶ return unless defined $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 0 24 24
155
156 24 return _xml_child_text( $root, 'Code' ), _xml_child_text( $root, 'Message' );
157 }
158
159 48 ▶ sub _xml_child_text ( $root, $name ) {
Subroutine _xml_child_text: called CC=3 SCAR=11.3
160 48 my ($node) = $root->findnodes( './*[local-name()="' . $name . '"]' );
161 48 ▶ return undef unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 48 48
162
163 48 my $value = $node->textContent;
164 48 $value =~ s/\A\s+|\s+\z//g;
165 48 ▶ return length $value ? $value : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 48 0 48
166 }
167 }
168
169 10 1;
170
171 __END__
« SDK/AppConfiguration/Uri.pm ↑ Summary SDK/AppConfiguration/CreateSnapshotOperation.pm »