Har/Page/PageTimings.pm

filter: Statementstmt 100% 80 / 80 Branchbran 100% 40 / 40 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 10 / 10 Podpod 80.0% 4 / 5 totaltotal 99.3% 144 / 145 CC 25 SCAR 16.1
CC
25
Cov
100%
TO_JSON
7.0
on_content_load
6.0
on_load
6.0
CRAP 5.0
« Har/Page.pm ↑ Summary Har/Entry/Response/Content.pm »
1 package Archive::Har::Page::PageTimings;
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  
7 10 our $VERSION = '0.21';
8  
9 142 ▶sub _DOES_NOT_APPLY { return -1 }
Subroutine _DOES_NOT_APPLY: called CC=1 SCAR=0.0
10  
11 14 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
12 14 my ( $class, $params ) = @_;
13 14 my $self = {};
14 14 bless $self, $class;
15 14 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 12 2 14
16 12 $self->on_content_load( $params->{onContentLoad} );
17 12 $self->on_load( $params->{onLoad} );
18 12 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 11 12
19 1 $self->comment( $params->{comment} );
20 }
21 12 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
22 23 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 2 21 23
23 2 $self->$key( $params->{$key} );
24 }
25 }
26 }
27 14 return $self;
28 }
29  
30 65 ▶sub on_content_load {
Subroutine on_content_load: called CC=6 SCAR=17.9
Pod documented
31 65 my ( $self, $new ) = @_;
32 65 my $old = $self->{onContentLoad};
33 65 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 20 45 65
34 20 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 16 4 20
35 16 ▶ if ( $new =~ /^(\d+(?:[.]\d+)?|-1)$/smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new =~ /^(\d+(?:[.]\d+)?|-1)$/msx) { } 15 1 16
36 15 $self->{onContentLoad} = $1 + 0;
37 }
38 else {
39 1 Carp::croak('on_content_load must be a positive number or -1');
40 }
41 }
42 else {
43 4 $self->{onContentLoad} = _DOES_NOT_APPLY();
44 }
45 }
46 64 ▶ if ( ( defined $old ) && ( $old == _DOES_NOT_APPLY() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old and $old == _DOES_NOT_APPLY()) { } 20 44 64
Condition100%3/3
defined $old and $old == _DOES_NOT_APPLY()
!ll&&!rl&&r
143020
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
47 20 return;
48 }
49 else {
50 44 return $old;
51 }
52 }
53  
54 67 ▶sub on_load {
Subroutine on_load: called CC=6 SCAR=17.9
Pod documented
55 67 my ( $self, $new ) = @_;
56 67 my $old = $self->{onLoad};
57 67 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 20 47 67
58 20 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 16 4 20
59 16 ▶ if ( $new =~ /^(\d+(?:[.]\d+)?|\-1)$/smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new =~ /^(\d+(?:[.]\d+)?|\-1)$/msx) { } 15 1 16
60 15 $self->{onLoad} = $1 + 0;
61 }
62 else {
63 1 Carp::croak('on_load must be a positive number or -1');
64 }
65 }
66 else {
67 4 $self->{onLoad} = _DOES_NOT_APPLY();
68 }
69 }
70 66 ▶ if ( ( defined $old ) && ( $old == _DOES_NOT_APPLY() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old and $old == _DOES_NOT_APPLY()) { } 18 48 66
Condition100%3/3
defined $old and $old == _DOES_NOT_APPLY()
!ll&&!rl&&r
143418
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
71 18 return;
72 }
73 else {
74 48 return $old;
75 }
76 }
77  
78 40 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
79 40 my ( $self, $new ) = @_;
80 40 my $old = $self->{comment};
81 40 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 39 40
82 1 $self->{comment} = $new;
83 }
84 40 return $old;
85 }
86  
87 22 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
88 22 my ( $self, $new ) = @_;
89  
90 22 my $name = $Archive::Har::Page::PageTimings::AUTOLOAD;
91 22 $name =~ s/.*://smx; # strip fully-qualified portion
92  
93 22 my $old;
94 22 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 6 16 22
elsif ($name eq 'DESTROY') { } 14 2 16
95 6 $old = $self->{$name};
96 6 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 4 2 6
97 4 $self->{$name} = $new;
98 }
99 }
100 elsif ( $name eq 'DESTROY' ) {
101 }
102 else {
103 2 Carp::croak(
104 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
105 );
106 }
107 20 return $old;
108 }
109  
110 31 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=7 SCAR=19.5
Pod undocumented
111 31 my ($self) = @_;
112 31 my $json = {};
113 31 ▶ if ( defined $self->on_content_load() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->on_content_load) { } 14 17 31
114 14 $json->{onContentLoad} = $self->on_content_load();
115 }
116 else {
117 17 $json->{onContentLoad} = _DOES_NOT_APPLY();
118 }
119 31 ▶ if ( defined $self->on_load() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->on_load) { } 16 15 31
120 16 $json->{onLoad} = $self->on_load();
121 }
122 else {
123 15 $json->{onLoad} = _DOES_NOT_APPLY();
124 }
125 31 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 8 23 31
126 8 $json->{comment} = $self->comment();
127 }
128 31 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
129 79 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 1 78 79
130 78 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 8 70 78
131 8 $json->{$key} = $self->{$key};
132 }
133 }
134 31 return $json;
135 }
136  
137 10 1;
138 __END__
« Har/Page.pm ↑ Summary Har/Entry/Response/Content.pm »