Net/Amazon/S3/Response.pm

filter: Statementstmt 94.3% 84 / 89 Branchbran 73.5% 25 / 34 Conditioncond 76.9% 10 / 13 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 89.6% 26 / 29 Podpod 80.0% 12 / 15 totaltotal 86.1% 162 / 188 CC 23 SCAR 9.4
CC
23
Cov
88%
findnodes
6.0
is_xml_content
5.2
is_error
3.0
CRAP 2.6
« Net/Amazon/S3/Request/Role/HTTP/Header/Copy_source.pm ↑ Summary Net/Amazon/S3/ACL/Grantee/Email.pm »
1 package Net::Amazon::S3::Response;
2 # ABSTRACT: Behaviour common to most S3 responses.
3 99 $Net::Amazon::S3::Response::VERSION = '0.992';
4 99 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 99 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 99 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 99 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 99 ▶use Net::Amazon::S3::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 99 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 99 has http_response => (
15 is => 'ro',
16 required => 1,
17 handles => [
18 qw[ code ],
19 qw[ message ],
20 qw[ is_success ],
21 qw[ is_redirect ],
22 qw[ status_line ],
23 qw[ content ],
24 qw[ decoded_content ],
25 qw[ header ],
26 qw[ headers ],
27 qw[ header_field_names ],
28 ],
29 );
30  
31 99 has xml_document => (
32 is => 'ro',
33 init_arg => undef,
34 lazy => 1,
35 builder => '_build_xml_document',
36 );
37  
38 99 has xpath_context => (
39 is => 'ro',
40 init_arg => undef,
41 lazy => 1,
42 builder => '_build_xpath_context',
43 );
44  
45 99 has error_code => (
46 is => 'ro',
47 init_arg => undef,
48 lazy => 1,
49 builder => '_build_error_code',
50 );
51  
52 99 has error_message => (
53 is => 'ro',
54 init_arg => undef,
55 lazy => 1,
56 builder => '_build_error_message',
57 );
58  
59 99 has error_resource => (
60 is => 'ro',
61 init_arg => undef,
62 lazy => 1,
63 builder => '_build_error_resource',
64 );
65  
66 99 has error_request_id => (
67 is => 'ro',
68 init_arg => undef,
69 lazy => 1,
70 builder => '_build_error_request_id',
71 );
72  
73 99 has _data => (
74 is => 'ro',
75 init_arg => undef,
76 lazy => 1,
77 builder => '_build_data',
78 );
79  
80 sub _parse_data;
81  
82 0 ▶sub connection {
Subroutine connection: not called CC=1 SCAR=6.9
Pod documented
83 0 return $_[0]->header ('Connection');
84 }
85  
86 3 ▶sub content_length {
Subroutine content_length: called CC=2 SCAR=6.9
Pod documented
87 3 ▶ return $_[0]->http_response->content_length || 0;
Condition100%2/2
$_[0]->http_response->content_length || 0
l!l
21
MC/DC100%1/1
$_[0]->http_response->content_length || 0
$_[0]->http_response->content_length
Truth table100%2/2
A
A= $_[0]->http_response->content_length
Aresult
11
00
88 }
89  
90 209 ▶sub content_type {
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
91 209 return $_[0]->http_response->content_type;
92 }
93  
94 0 ▶sub date {
Subroutine date: not called CC=1 SCAR=6.9
Pod undocumented
95 0 return $_[0]->header ('Date');
96 }
97  
98 4 ▶sub etag {
Subroutine etag: called CC=1 SCAR=0.0
Pod documented
99 4 return $_[0]->_decode_etag ($_[0]->header ('ETag'));
100 }
101  
102 1 ▶sub server {
Subroutine server: called CC=1 SCAR=0.0
Pod documented
103 1 return $_[0]->header ('Server');
104 }
105  
106 1 ▶sub delete_marker {
Subroutine delete_marker: called CC=1 SCAR=0.0
Pod documented
107 1 return $_[0]->header (Net::Amazon::S3::Constants::HEADER_DELETE_MARKER);
108 }
109  
110 1 ▶sub id_2 {
Subroutine id_2: called CC=1 SCAR=0.0
Pod documented
111 1 return $_[0]->header (Net::Amazon::S3::Constants::HEADER_ID_2);
112 }
113  
114 2 ▶sub request_id {
Subroutine request_id: called CC=1 SCAR=0.0
Pod documented
115 2 return $_[0]->header (Net::Amazon::S3::Constants::HEADER_REQUEST_ID);
116 }
117  
118 1 ▶sub version_id {
Subroutine version_id: called CC=1 SCAR=0.0
Pod documented
119 1 return $_[0]->header (Net::Amazon::S3::Constants::HEADER_VERSION_ID);
120 }
121  
122 206 ▶sub is_xml_content {
Subroutine is_xml_content: called CC=5 SCAR=16.4
Pod documented
123 206 my ($self) = @_;
124  
125 206 my $decoded_content = $self->decoded_content;
126 206 my $content_type = $self->content_type;
127  
128 206 ▶ return $content_type =~ m{[/+]xml\b} && $decoded_content if $content_type;
Branch: 1 branch
BranchTrueFalseTotal
if $content_type 200 6 206
Condition100%3/3
$content_type =~ m[[/+]xml\b] && $decoded_content
!ll&&!rl&&r
973118
MC/DC100%2/2
$content_type =~ m[[/+]xml\b] && $decoded_content
$content_type =~ m[[/+]xml\b] $decoded_content
Truth table100%3/3
A && B
A= $content_type =~ m[[/+]xml\b]B= $decoded_content
ABresult
0X0
100
111
129 6 ▶ return 1 if $decoded_content && $decoded_content =~ /^<\?xml\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $decoded_content and $decoded_content =~ /^<\?xml\b/ 0 6 6
Condition33%1/3
$decoded_content and $decoded_content =~ /^<\?xml\b/
!ll&&!rl&&r
600
MC/DC0%0/2
$decoded_content and $decoded_content =~ /^<\?xml\b/
$decoded_content $decoded_content =~ /^<\?xml\b/
Truth table33%1/3
A and B
A= $decoded_contentB= $decoded_content =~ /^<\?xml\b/
ABresult
0X0
100
111
130 6 return 0;
131 }
132  
133 434 ▶sub is_error {
Subroutine is_error: called CC=3 SCAR=11.0
Pod documented
134 434 my ($self) = @_;
135  
136 434 ▶ return 1 if $self->http_response->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $self->http_response->is_error 343 91 434
137 91 ▶ return 1 if $self->findvalue ('/Error');
Branch: 1 branch
BranchTrueFalseTotal
if $self->findvalue("/Error") 0 91 91
138 91 return;
139 }
140  
141 3 ▶sub is_internal_response {
Subroutine is_internal_response: called CC=2 SCAR=7.0
Pod documented
142 3 my ($self) = @_;
143  
144 3 my $header = $self->header ('Client-Warning');
145 3 ▶ return !! ($header && $header eq 'Internal response');
Condition66%2/3
$header && $header eq 'Internal response'
!ll&&!rl&&r
201
MC/DC50%1/2
$header && $header eq 'Internal response'
$header $header eq 'Internal response'
Truth table66%2/3
A && B
A= $headerB= $header eq 'Internal response'
ABresult
0X0
100
111
146 }
147  
148 239 ▶sub findvalue {
Subroutine findvalue: called CC=2 SCAR=6.9
Pod undocumented
149 239 my ($self, @path) = @_;
150  
151 239 ▶ return '' unless $self->xpath_context;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xpath_context 52 187 239
152 187 $self->xpath_context->findvalue (@path);
153 }
154  
155 0 ▶sub findnodes {
Subroutine findnodes: not called CC=2 SCAR=17.9
Pod undocumented
156 0 my ($self, @path) = @_;
157  
158 0 ▶ return unless $self->xpath_context;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xpath_context 0 0 0
159 0 $self->xpath_context->findnodes (@path);
160 }
161  
162 14 ▶sub _build_data {
Subroutine _build_data: called CC=2 SCAR=7.2
163 14 my ($self) = @_;
164  
165 14 ▶ return $self->is_success
Branch: 1 branch
BranchTrueFalseTotal
$self->is_success ? : 14 0 14
166 ? $self->_parse_data
167 : undef
168 ;
169 }
170 111 ▶sub _build_error_code {
Subroutine _build_error_code: called CC=3 SCAR=11.0
171 111 my ($self) = @_;
172  
173 return
174 111 ▶ unless $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_error 0 111 111
175  
176 111 ▶ return $self->http_response->code
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xpath_context 34 77 111
177 unless $self->xpath_context;
178  
179 77 return $self->findvalue ('/Error/Code');
180 }
181  
182 101 ▶sub _build_error_message {
Subroutine _build_error_message: called CC=3 SCAR=11.0
183 101 my ($self) = @_;
184  
185 return
186 101 ▶ unless $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_error 0 101 101
187  
188 101 ▶ return $self->http_response->message
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xpath_context 32 69 101
189 unless $self->xpath_context;
190  
191 69 return $self->findvalue ('/Error/Message');
192 }
193  
194 2 ▶sub _build_error_resource {
Subroutine _build_error_resource: called CC=3 SCAR=11.0
195 2 my ($self) = @_;
196  
197 return
198 2 ▶ unless $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_error 0 2 2
199  
200 2 ▶ return "${\ $self->http_response->request->uri }"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xpath_context 1 1 2
201 unless $self->xpath_context;
202  
203 1 return $self->findvalue ('/Error/Resource');
204 }
205  
206 2 ▶sub _build_error_request_id {
Subroutine _build_error_request_id: called CC=3 SCAR=11.0
207 2 my ($self) = @_;
208  
209 return
210 2 ▶ unless $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_error 0 2 2
211  
212 2 ▶ return $self->request_id
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xpath_context 1 1 2
213 unless $self->xpath_context;
214  
215 1 return $self->findvalue ('/Error/RequestId');
216 }
217  
218 201 ▶sub _build_xml_document {
Subroutine _build_xml_document: called CC=2 SCAR=6.9
219 201 my ($self) = @_;
220  
221 201 ▶ return unless $self->is_xml_content;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_xml_content 86 115 201
222  
223 # TODO: A 200 OK response can contain valid or invalid XML
224 115 return XML::LibXML->new->parse_string ($self->http_response->decoded_content);
225 }
226  
227 201 ▶sub _build_xpath_context {
Subroutine _build_xpath_context: called CC=3 SCAR=11.0
228 201 my ($self) = @_;
229  
230 201 my $doc = $self->xml_document;
231 201 ▶ return unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 86 115 201
232  
233 115 my $xpc = XML::LibXML::XPathContext->new ($doc);
234  
235 115 ▶ my $s3_ns = $doc->documentElement->lookupNamespaceURI
Condition100%2/2
$doc->documentElement->lookupNamespaceURI || 'http://s3.amazonaws.com/doc/2006-03-01/'
l!l
1897
MC/DC100%1/1
$doc->documentElement->lookupNamespaceURI || 'http://s3.amazonaws.com/doc/2006-03-01/'
$doc->documentElement->lookupNamespaceURI
Truth table100%2/2
A
A= $doc->documentElement->lookupNamespaceURI
Aresult
11
00
236 || 'http://s3.amazonaws.com/doc/2006-03-01/';
237 115 $xpc->registerNs (s3 => $s3_ns);
238  
239 115 return $xpc;
240 }
241  
242 4 ▶sub _decode_etag {
Subroutine _decode_etag: called CC=1 SCAR=0.0
243 4 my ($self, $etag) = @_;
244  
245 4 $etag =~ s/ (?:^") | (?:"$) //gx;
246 4 return $etag;
247 }
248  
249 99 1;
250  
251 __END__
« Net/Amazon/S3/Request/Role/HTTP/Header/Copy_source.pm ↑ Summary Net/Amazon/S3/ACL/Grantee/Email.pm »