Har/Entry.pm

filter: Statementstmt 100% 155 / 155 Branchbran 100% 68 / 68 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 21 / 21 Podpod 91.6% 11 / 12 totaltotal 99.6% 260 / 261 CC 39 SCAR 15.3
CC
39
Cov
100%
TO_JSON
9.0
new
8.0
started_date_time
6.0
CRAP 4.6
« Har/Entry/Cache/Request.pm ↑ Summary Har/Entry/Request/PostData/Params.pm »
1 package Archive::Har::Entry;
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::Request();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Archive::Har::Entry::Response();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Archive::Har::Entry::Cache();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Archive::Har::Entry::Timings();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 our $VERSION = '0.21';
12  
13 32 ▶sub _DOES_NOT_APPLY { return -1 }
Subroutine _DOES_NOT_APPLY: called CC=1 SCAR=0.0
14  
15 177 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
16 177 my ( $class, $params ) = @_;
17 177 my $self = {};
18 177 bless $self, $class;
19 177 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 172 5 177
20 172 ▶ if ( defined $params->{pageref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"pageref"}) 137 35 172
21 137 $self->pageref( $params->{pageref} );
22 }
23 172 $self->started_date_time( $params->{startedDateTime} );
24 $self->request(
25 172 Archive::Har::Entry::Request->new( $params->{request} ) );
26 $self->response(
27 172 Archive::Har::Entry::Response->new( $params->{response} ) );
28 172 $self->cache( Archive::Har::Entry::Cache->new( $params->{cache} ) );
29 $self->timings(
30 172 Archive::Har::Entry::Timings->new( $params->{timings} ) );
31 172 ▶ if ( defined $params->{serverIPAddress} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"serverIPAddress"}) 117 55 172
32 117 $self->server_ip_address( $params->{serverIPAddress} );
33 }
34 172 ▶ if ( defined $params->{connection} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"connection"}) 111 61 172
35 111 $self->connection( $params->{connection} );
36 }
37 172 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 171 172
38 1 $self->comment( $params->{comment} );
39 }
40 172 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
41 1381 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 1 1380 1381
42 1 $self->$key( $params->{$key} );
43 }
44 }
45 }
46 177 return $self;
47 }
48  
49 1056 ▶sub pageref {
Subroutine pageref: called CC=2 SCAR=6.9
Pod documented
50 1056 my ( $self, $new ) = @_;
51 1056 my $old = $self->{pageref};
52 1056 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 142 914 1056
53 142 $self->{pageref} = $new;
54 }
55 1056 return $old;
56 }
57  
58 1126 ▶sub started_date_time {
Subroutine started_date_time: called CC=6 SCAR=17.9
Pod documented
59 1126 my ( $self, $new ) = @_;
60 1126 my $old = $self->{startedDateTime};
61 1126 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 179 947 1126
62 179 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 176 3 179
63 176 my $date_regex = qr/\d{4}[-]\d{2}[-]\d{2}/smx;
64 176 my $time_regex = qr/\d{2}:\d{2}:\d{2}[.]\d+/smx;
65 176 my $zone_regex = qr/(?:[+]\d{2}:\d{2}|Z)/smx;
66 176 ▶ if ( $new =~ /^${date_regex}T${time_regex}${zone_regex}$/smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new =~ /^${date_regex}T$time_regex$zone_regex$/msx) { } 175 1 176
67 175 $self->{startedDateTime} = $new;
68 }
69 else {
70 1 Carp::croak('started_date_time is not formatted correctly');
71 }
72 }
73 else {
74 3 $self->{startedDateTime} = '0000-00-00T00:00:00.0+00:00';
75 }
76 }
77 1125 ▶ if ( ( defined $old ) && ( $old eq '0000-00-00T00:00:00.0+00:00' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old and $old eq '0000-00-00T00:00:00.0+00:00') { } 33 1092 1125
Condition100%3/3
defined $old and $old eq "0000-00-00T00:00:00.0+00:00"
!ll&&!rl&&r
17791533
MC/DC100%2/2
defined $old and $old eq "0000-00-00T00:00:00.0+00:00"
defined $old $old eq "0000-00-00T00:00:00.0+00:00"
Truth table100%3/3
A and B
A= defined $oldB= $old eq "0000-00-00T00:00:00.0+00:00"
ABresult
0X0
100
111
78 33 return;
79 }
80 else {
81 1092 return $old;
82 }
83 }
84  
85 492 ▶sub time {
Subroutine time: called CC=4 SCAR=13.9
Pod documented
86 492 my ($self) = @_;
87 492 my $timings = $self->timings();
88 492 my $total = 0;
89 492 my $found = 0;
90 492 foreach my $timing (
91 $timings->blocked(), $timings->dns(),
92 $timings->connect(), $timings->send(),
93 $timings->wait(), $timings->receive(),
94 $timings->ssl(),
95 )
96 {
97 2936 ▶ if ( defined $timing ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timing) 2555 381 2936
98 2555 $found = 1;
99 2555 $total += $timing;
100 }
101 }
102 492 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 460 32 492
103 460 return $total;
104 }
105 else {
106 32 return _DOES_NOT_APPLY();
107 }
108 }
109  
110 718 ▶sub request {
Subroutine request: called CC=3 SCAR=11.0
Pod documented
111 718 my ( $self, $new ) = @_;
112 718 my $old = $self->{request};
113 718 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 177 541 718
114 177 $self->{request} = $new;
115 }
116 718 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 536 182 718
117 536 return $old;
118 }
119 else {
120 182 return Archive::Har::Entry::Request->new();
121 }
122 }
123  
124 699 ▶sub response {
Subroutine response: called CC=3 SCAR=11.0
Pod documented
125 699 my ( $self, $new ) = @_;
126 699 my $old = $self->{response};
127 699 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 177 522 699
128 177 $self->{response} = $new;
129 }
130 699 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 517 182 699
131 517 return $old;
132 }
133 else {
134 182 return Archive::Har::Entry::Response->new();
135 }
136 }
137  
138 674 ▶sub cache {
Subroutine cache: called CC=3 SCAR=11.0
Pod documented
139 674 my ( $self, $new ) = @_;
140 674 my $old = $self->{cache};
141 674 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 172 502 674
142 172 $self->{cache} = $new;
143 }
144 674 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 502 172 674
145 502 return $old;
146 }
147 else {
148 172 return Archive::Har::Entry::Cache->new();
149 }
150 }
151  
152 1175 ▶sub timings {
Subroutine timings: called CC=3 SCAR=11.0
Pod documented
153 1175 my ( $self, $new ) = @_;
154 1175 my $old = $self->{timings};
155 1175 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 177 998 1175
156 177 $self->{timings} = $new;
157 }
158 1175 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 998 177 1175
159 998 return $old;
160 }
161 else {
162 177 return Archive::Har::Entry::Timings->new();
163 }
164 }
165  
166 832 ▶sub server_ip_address {
Subroutine server_ip_address: called CC=2 SCAR=6.9
Pod documented
167 832 my ( $self, $new ) = @_;
168 832 my $old = $self->{serverIPAddress};
169 832 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 117 715 832
170 117 $self->{serverIPAddress} = $new;
171 }
172 832 return $old;
173 }
174  
175 820 ▶sub connection {
Subroutine connection: called CC=2 SCAR=6.9
Pod documented
176 820 my ( $self, $new ) = @_;
177 820 my $old = $self->{connection};
178 820 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 111 709 820
179 111 $self->{connection} = $new;
180 }
181 820 return $old;
182 }
183  
184 500 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
185 500 my ( $self, $new ) = @_;
186 500 my $old = $self->{comment};
187 500 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 499 500
188 1 $self->{comment} = $new;
189 }
190 500 return $old;
191 }
192  
193 180 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
194 180 my ( $self, $new ) = @_;
195  
196 180 my $name = $Archive::Har::Entry::AUTOLOAD;
197 180 $name =~ s/.*://smx; # strip fully-qualified portion
198  
199 180 my $old;
200 180 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 4 176 180
elsif ($name eq 'DESTROY') { } 175 1 176
201 4 $old = $self->{$name};
202 4 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 1 4
203 3 $self->{$name} = $new;
204 }
205 }
206 elsif ( $name eq 'DESTROY' ) {
207 }
208 else {
209 1 Carp::croak(
210 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
211 );
212 }
213 179 return $old;
214 }
215  
216 489 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=9 SCAR=22.0
Pod undocumented
217 489 my ($self) = @_;
218 489 my $json = {};
219 489 ▶ if ( defined $self->pageref() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->pageref) 424 65 489
220 424 $json->{pageref} = $self->pageref();
221 }
222 489 ▶ if ( defined $self->started_date_time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->started_date_time) { } 457 32 489
223 457 $json->{startedDateTime} = $self->started_date_time();
224 }
225 else {
226 32 $json->{startedDateTime} = '0000-00-00T00:00:00.0+00:00';
227 }
228 489 $json->{time} = $self->time();
229 489 $json->{request} = $self->request();
230 489 $json->{response} = $self->response();
231 489 $json->{cache} = $self->cache();
232 489 $json->{timings} = $self->timings();
233 489 ▶ if ( defined $self->server_ip_address() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->server_ip_address) 225 264 489
234 225 $json->{serverIPAddress} = $self->server_ip_address();
235 }
236 489 ▶ if ( defined $self->connection() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->connection) 219 270 489
237 219 $json->{connection} = $self->connection();
238 }
239 489 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 10 479 489
240 10 $json->{comment} = $self->comment();
241 }
242 489 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
243 3333 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 1 3332 3333
244 3332 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 9 3323 3332
245 9 $json->{$key} = $self->{$key};
246 }
247 }
248 489 return $json;
249 }
250  
251 10 1;
252 __END__
« Har/Entry/Cache/Request.pm ↑ Summary Har/Entry/Request/PostData/Params.pm »