Har/Entry/Response.pm

filter: Statementstmt 100% 156 / 156 Branchbran 100% 60 / 60 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 20 / 20 Podpod 91.6% 11 / 12 totaltotal 99.6% 257 / 258 CC 37 SCAR 14.0
CC
37
Cov
100%
new
7.0
TO_JSON
7.0
headers_size
5.0
CRAP 4.1
« Har/Entry/Request/PostData/Params.pm ↑ Summary Har/Entry/Request/QueryString.pm »
1 package Archive::Har::Entry::Response;
2  
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Archive::Har::Entry::Header();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Archive::Har::Entry::Cookie();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Archive::Har::Entry::Response::Content();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 our $VERSION = '0.21';
11  
12 1940 ▶sub _DOES_NOT_APPLY { return -1 }
Subroutine _DOES_NOT_APPLY: called CC=1 SCAR=0.0
13  
14 354 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
15 354 my ( $class, $params ) = @_;
16 354 my $self = {};
17 354 bless $self, $class;
18 354 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 171 183 354
19 171 $self->status( $params->{status} );
20 171 $self->status_text( $params->{statusText} );
21 171 $self->http_version( $params->{httpVersion} );
22 171 my @cookies;
23 171 foreach my $cookie ( @{ $params->{cookies} } ) {
24 9 push @cookies, Archive::Har::Entry::Cookie->new($cookie);
25 }
26 171 $self->cookies( \@cookies );
27 171 my @headers;
28 171 foreach my $header ( @{ $params->{headers} } ) {
29 1718 push @headers, Archive::Har::Entry::Header->new($header);
30 }
31 171 $self->headers( \@headers );
32 $self->content(
33 171 Archive::Har::Entry::Response::Content->new( $params->{content} ) );
34 171 $self->redirect_url( $params->{redirectURL} );
35 171 $self->headers_size( $params->{headersSize} );
36 171 $self->body_size( $params->{bodySize} );
37 171 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 170 171
38 1 $self->comment( $params->{comment} );
39 }
40 171 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
41 1549 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 15 1534 1549
42 15 $self->$key( $params->{$key} );
43 }
44 }
45 }
46 354 return $self;
47 }
48  
49 666 ▶sub status {
Subroutine status: called CC=3 SCAR=11.0
Pod documented
50 666 my ( $self, $new ) = @_;
51 666 my $old = $self->{status};
52 666 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 490 666
53 176 $self->{status} = $new;
54 }
55 666 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 458 208 666
56 458 return $old;
57 }
58 else {
59 208 return 0;
60 }
61 }
62  
63 666 ▶sub status_text {
Subroutine status_text: called CC=3 SCAR=11.0
Pod documented
64 666 my ( $self, $new ) = @_;
65 666 my $old = $self->{statusText};
66 666 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 490 666
67 176 $self->{statusText} = $new;
68 }
69 666 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 458 208 666
70 458 return $old;
71 }
72 else {
73 208 return 'Unknown';
74 }
75 }
76  
77 666 ▶sub http_version {
Subroutine http_version: called CC=3 SCAR=11.0
Pod documented
78 666 my ( $self, $new ) = @_;
79 666 my $old = $self->{httpVersion};
80 666 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 490 666
81 176 $self->{httpVersion} = $new;
82 }
83 666 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 458 208 666
84 458 return $old;
85 }
86 else {
87 208 return 'Unknown';
88 }
89 }
90  
91 667 ▶sub headers {
Subroutine headers: called CC=3 SCAR=11.0
Pod documented
92 667 my ( $self, $new ) = @_;
93 667 my $old = $self->{headers};
94 667 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 491 667
95 176 $self->{headers} = $new;
96 }
97 667 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 481 186 667
98 481 return @{$old};
99 }
100 else {
101 186 return ();
102 }
103 }
104  
105 672 ▶sub cookies {
Subroutine cookies: called CC=3 SCAR=11.0
Pod documented
106 672 my ( $self, $new ) = @_;
107 672 my $old = $self->{cookies};
108 672 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 496 672
109 176 $self->{cookies} = $new;
110 }
111 672 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 486 186 672
112 486 return @{$old};
113 }
114 else {
115 186 return ();
116 }
117 }
118  
119 673 ▶sub content {
Subroutine content: called CC=2 SCAR=6.9
Pod documented
120 673 my ( $self, $new ) = @_;
121 673 my $old = $self->{content};
122 673 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 497 673
123 176 $self->{content} = Archive::Har::Entry::Response::Content->new($new);
124 }
125 673 return $old;
126 }
127  
128 667 ▶sub redirect_url {
Subroutine redirect_url: called CC=2 SCAR=6.9
Pod documented
129 667 my ( $self, $new ) = @_;
130 667 my $old = $self->{redirectURL};
131 667 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 491 667
132 176 $self->{redirectURL} = $new;
133 }
134 667 return $old;
135 }
136  
137 1109 ▶sub headers_size {
Subroutine headers_size: called CC=5 SCAR=16.1
Pod documented
138 1109 my ( $self, $new ) = @_;
139 1109 my $old = $self->{headersSize};
140 1109 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 933 1109
141 176 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 175 1 176
142 175 $self->{headersSize} = $new + 0;
143 }
144 else {
145 1 $self->{headersSize} = _DOES_NOT_APPLY();
146 }
147 }
148 1109 ▶ if ( ( defined $old ) && ( $old == _DOES_NOT_APPLY() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old and $old == _DOES_NOT_APPLY()) { } 36 1073 1109
Condition100%3/3
defined $old and $old == _DOES_NOT_APPLY()
!ll&&!rl&&r
18688736
MC/DC100%2/2
defined $old and $old == _DOES_NOT_APPLY()
defined $old $old == _DOES_NOT_APPLY()
Truth table100%3/3
A and B
A= defined $oldB= $old == _DOES_NOT_APPLY()
ABresult
0X0
100
111
149 36 return;
150 }
151 else {
152 1073 return $old;
153 }
154 }
155  
156 1117 ▶sub body_size {
Subroutine body_size: called CC=5 SCAR=16.1
Pod documented
157 1117 my ( $self, $new ) = @_;
158 1117 my $old = $self->{bodySize};
159 1117 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 176 941 1117
160 176 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 175 1 176
161 175 $self->{bodySize} = $new + 0;
162 }
163 else {
164 1 $self->{bodySize} = _DOES_NOT_APPLY();
165 }
166 }
167 1117 ▶ if ( ( defined $old ) && ( $old == _DOES_NOT_APPLY() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old and $old == _DOES_NOT_APPLY()) { } 28 1089 1117
Condition100%3/3
defined $old and $old == _DOES_NOT_APPLY()
!ll&&!rl&&r
18690328
MC/DC100%2/2
defined $old and $old == _DOES_NOT_APPLY()
defined $old $old == _DOES_NOT_APPLY()
Truth table100%3/3
A and B
A= defined $oldB= $old == _DOES_NOT_APPLY()
ABresult
0X0
100
111
168 28 return;
169 }
170 else {
171 1089 return $old;
172 }
173 }
174  
175 512 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
176 512 my ( $self, $new ) = @_;
177 512 my $old = $self->{comment};
178 512 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 511 512
179 1 $self->{comment} = $new;
180 }
181 512 return $old;
182 }
183  
184 371 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
185 371 my ( $self, $new ) = @_;
186  
187 371 my $name = $Archive::Har::Entry::Response::AUTOLOAD;
188 371 $name =~ s/.*://smx; # strip fully-qualified portion
189  
190 371 my $old;
191 371 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 18 353 371
elsif ($name eq 'DESTROY') { } 352 1 353
192 18 $old = $self->{$name};
193 18 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 17 1 18
194 17 $self->{$name} = $new;
195 }
196 }
197 elsif ( $name eq 'DESTROY' ) {
198 }
199 else {
200 1 Carp::croak(
201 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
202 );
203 }
204 370 return $old;
205 }
206  
207 489 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=7 SCAR=19.5
Pod undocumented
208 489 my ($self) = @_;
209 489 my $json = {};
210 489 $json->{status} = $self->status();
211 489 $json->{statusText} = $self->status_text();
212 489 $json->{httpVersion} = $self->http_version();
213 489 $json->{cookies} = [ $self->cookies() ];
214 489 $json->{headers} = [ $self->headers() ];
215 489 $json->{content} = $self->content();
216 489 $json->{redirectURL} = $self->redirect_url();
217 489 ▶ if ( defined $self->headers_size() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->headers_size) { } 443 46 489
218 443 $json->{headersSize} = $self->headers_size();
219 }
220 else {
221 46 $json->{headersSize} = _DOES_NOT_APPLY();
222 }
223 489 $json->{headersSize} += 0;
224 489 ▶ if ( defined $self->body_size() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->body_size) { } 451 38 489
225 451 $json->{bodySize} = $self->body_size();
226 }
227 else {
228 38 $json->{bodySize} = _DOES_NOT_APPLY();
229 }
230 489 $json->{bodySize} += 0;
231 489 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 22 467 489
232 22 $json->{comment} = $self->comment();
233 }
234 489 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
235 4369 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 89 4280 4369
236 4280 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 35 4245 4280
237 35 $json->{$key} = $self->{$key};
238 }
239 }
240 489 return $json;
241 }
242  
243 10 1;
244 __END__
« Har/Entry/Request/PostData/Params.pm ↑ Summary Har/Entry/Request/QueryString.pm »