Har/Page.pm

filter: Statementstmt 100% 97 / 97 Branchbran 97.8% 45 / 46 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 12 / 12 Podpod 71.4% 5 / 7 totaltotal 98.2% 167 / 170 CC 28 SCAR 16.6
CC
28
Cov
99%
TO_JSON
8.0
new
8.0
started_date_time
6.0
CRAP 5.3
« Har/Entry/Request/PostData.pm ↑ Summary Har/Page/PageTimings.pm »
1 package Archive::Har::Page;
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::Page::PageTimings();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 our $VERSION = '0.21';
9  
10 14 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod undocumented
11 14 my ( $class, $params ) = @_;
12 14 my $self = {};
13 14 bless $self, $class;
14 14 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 12 2 14
15 12 $self->id( $params->{id} );
16 12 ▶ if ( defined $params->{title} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"title"}) 10 2 12
17 10 $self->title( $params->{title} );
18 }
19 12 ▶ if ( defined $params->{startedDateTime} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"startedDateTime"}) 10 2 12
20 10 $self->started_date_time( $params->{startedDateTime} );
21 }
22 $self->page_timings(
23 Archive::Har::Page::PageTimings->new(
24 $params->{pageTimings} || {}
25 )
26 12 ▶ );
Condition100%2/2
$params->{'pageTimings'} || {}
l!l
111
MC/DC100%1/1
$params->{'pageTimings'} || {}
$params->{'pageTimings'}
Truth table100%2/2
A
A= $params->{'pageTimings'}
Aresult
11
00
27 12 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 11 12
28 1 $self->comment( $params->{comment} );
29 }
30 12 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
31 45 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 1 44 45
32 1 $self->$key( $params->{$key} );
33 }
34 }
35 }
36 14 return $self;
37 }
38  
39 77 ▶sub id {
Subroutine id: called CC=2 SCAR=6.9
Pod documented
40 77 my ( $self, $new ) = @_;
41 77 my $old = $self->{id};
42 77 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 14 63 77
43 14 $self->{id} = $new;
44 }
45 77 return $old;
46 }
47  
48 62 ▶sub title {
Subroutine title: called CC=3 SCAR=11.0
Pod documented
49 62 my ( $self, $new ) = @_;
50 62 my $old = $self->{title};
51 62 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 12 50 62
52 12 $self->{title} = $new;
53 }
54 62 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 37 25 62
55 37 return $old;
56 }
57 else {
58 25 return;
59 }
60 }
61  
62 64 ▶sub started_date_time {
Subroutine started_date_time: called CC=6 SCAR=17.9
Pod documented
63 64 my ( $self, $new ) = @_;
64 64 my $old = $self->{startedDateTime};
65 64 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 14 50 64
66 14 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 13 1 14
67 13 my $date_regex = qr/\d{4}[-]\d{2}[-]\d{2}/smx;
68 13 my $time_regex = qr/\d{2}:\d{2}:\d{2}[.]\d+/smx;
69 13 my $zone_regex = qr/(?:[+]\d{2}:\d{2}|Z)/smx;
70 13 ▶ if ( $new =~ /^${date_regex}T${time_regex}${zone_regex}$/smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new =~ /^${date_regex}T$time_regex$zone_regex$/msx) { } 12 1 13
71 12 $self->{startedDateTime} = $new;
72 }
73 else {
74 1 Carp::croak('started_date_time is not formatted correctly');
75 }
76 }
77 else {
78 1 $self->{startedDateTime} = '0000-00-00T00:00:00.0+00:00';
79 }
80 }
81 63 ▶ 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') { } 5 58 63
Condition100%3/3
defined $old and $old eq "0000-00-00T00:00:00.0+00:00"
!ll&&!rl&&r
21375
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
82 5 return;
83 }
84 else {
85 58 return $old;
86 }
87 }
88  
89 63 ▶sub page_timings {
Subroutine page_timings: called CC=2 SCAR=6.9
Pod documented
90 63 my ( $self, $new ) = @_;
91 63 my $old = $self->{pageTimings};
92 63 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 14 49 63
93 14 $self->{pageTimings} = $new;
94 }
95 63 return $old;
96 }
97  
98 40 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
99 40 my ( $self, $new ) = @_;
100 40 my $old = $self->{comment};
101 40 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 39 40
102 1 $self->{comment} = $new;
103 }
104 40 return $old;
105 }
106  
107 19 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
108 19 my ( $self, $new ) = @_;
109  
110 19 my $name = $Archive::Har::Page::AUTOLOAD;
111 19 $name =~ s/.*://smx; # strip fully-qualified portion
112  
113 19 my $old;
114 19 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 4 15 19
elsif ($name eq 'DESTROY') { } 14 1 15
115 4 $old = $self->{$name};
116 4 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 1 4
117 3 $self->{$name} = $new;
118 }
119 }
120 elsif ( $name eq 'DESTROY' ) {
121 }
122 else {
123 1 Carp::croak(
124 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
125 );
126 }
127 18 return $old;
128 }
129  
130 31 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=8 SCAR=20.8
Pod undocumented
131 31 my ($self) = @_;
132 31 my $json = { pageTimings => $self->page_timings(), };
133 31 ▶ if ( defined $self->title() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->title) { } 18 13 31
134 18 $json->{title} = $self->title();
135 }
136 else {
137 13 $json->{title} = 'Unknown';
138 }
139 31 ▶ if ( defined $self->started_date_time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->started_date_time) { } 18 13 31
140 18 $json->{startedDateTime} = $self->started_date_time();
141 }
142 else {
143 13 $json->{startedDateTime} = '0000-00-00T00:00:00.0+00:00';
144 }
145 31 ▶ if ( defined $self->id() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->id) 31 0 31
146 31 $json->{id} = $self->id();
147 }
148 31 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 8 23 31
149 8 $json->{comment} = $self->comment();
150 }
151 31 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
152 119 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 1 118 119
153 118 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 7 111 118
154 7 $json->{$key} = $self->{$key};
155 }
156 }
157 31 return $json;
158 }
159  
160 10 1;
161 __END__
« Har/Entry/Request/PostData.pm ↑ Summary Har/Page/PageTimings.pm »