Har/Creator.pm

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