Har/Entry/Cookie.pm

filter: Statementstmt 100% 115 / 115 Branchbran 100% 66 / 66 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 80.0% 8 / 10 totaltotal 99.0% 204 / 206 CC 36 SCAR 18.6
CC
36
Cov
100%
TO_JSON
12.0
new
10.0
http_only
4.0
CRAP 6.4
« Har.pm ↑ Summary Har/Entry/Timings.pm »
1 package Archive::Har::Entry::Cookie;
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 JSON();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 our $VERSION = '0.21';
9  
10 55 ▶sub new {
Subroutine new: called CC=10 SCAR=23.0
Pod undocumented
11 55 my ( $class, $params ) = @_;
12 55 my $self = {};
13 55 bless $self, $class;
14 55 ▶ if ( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 54 1 55
15 54 $self->name( $params->{name} );
16 54 $self->value( $params->{value} );
17 54 ▶ if ( defined $params->{path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"path"}) 21 33 54
18 21 $self->path( $params->{path} );
19 }
20 54 ▶ if ( defined $params->{domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"domain"}) 19 35 54
21 19 $self->domain( $params->{domain} );
22 }
23 54 ▶ if ( defined $params->{expires} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"expires"}) 15 39 54
24 15 $self->expires( $params->{expires} );
25 }
26 54 ▶ if ( defined $params->{httpOnly} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"httpOnly"}) 28 26 54
27 28 $self->http_only( $params->{httpOnly} );
28 }
29 54 ▶ if ( defined $params->{secure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"secure"}) 25 29 54
30 25 $self->secure( $params->{secure} );
31 }
32 54 ▶ if ( defined $params->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"comment"}) 1 53 54
33 1 $self->comment( $params->{comment} );
34 }
35 54 foreach my $key ( sort { $a cmp $b } keys %{$params} ) {
36 223 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 1 222 223
37 1 $self->$key( $params->{$key} );
38 }
39 }
40 }
41 55 return $self;
42 }
43  
44 133 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod documented
45 133 my ( $self, $new ) = @_;
46 133 my $old = $self->{name};
47 133 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 55 78 133
48 55 $self->{name} = $new;
49 }
50 133 return $old;
51 }
52  
53 133 ▶sub value {
Subroutine value: called CC=2 SCAR=6.9
Pod documented
54 133 my ( $self, $new ) = @_;
55 133 my $old = $self->{value};
56 133 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 55 78 133
57 55 $self->{value} = $new;
58 }
59 133 return $old;
60 }
61  
62 119 ▶sub path {
Subroutine path: called CC=2 SCAR=6.9
Pod documented
63 119 my ( $self, $new ) = @_;
64 119 my $old = $self->{path};
65 119 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 21 98 119
66 21 $self->{path} = $new;
67 }
68 119 return $old;
69 }
70  
71 113 ▶sub domain {
Subroutine domain: called CC=2 SCAR=6.9
Pod documented
72 113 my ( $self, $new ) = @_;
73 113 my $old = $self->{domain};
74 113 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 19 94 113
75 19 $self->{domain} = $new;
76 }
77 113 return $old;
78 }
79  
80 107 ▶sub expires {
Subroutine expires: called CC=2 SCAR=6.9
Pod documented
81 107 my ( $self, $new ) = @_;
82 107 my $old = $self->{expires};
83 107 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 15 92 107
84 15 $self->{expires} = $new;
85 }
86 107 return $old;
87 }
88  
89 134 ▶sub http_only {
Subroutine http_only: called CC=4 SCAR=13.9
Pod documented
90 134 my ( $self, $new ) = @_;
91 134 my $old = $self->{httpOnly};
92 134 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 28 106 134
93 28 $self->{httpOnly} = $new;
94 }
95 134 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 60 74 134
96 60 ▶ return $old ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 32 28 60
97 }
98 else {
99 74 return;
100 }
101 }
102  
103 128 ▶sub secure {
Subroutine secure: called CC=4 SCAR=13.9
Pod documented
104 128 my ( $self, $new ) = @_;
105 128 my $old = $self->{secure};
106 128 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 25 103 128
107 25 $self->{secure} = $new;
108 }
109 128 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 53 75 128
110 53 ▶ return $old ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 25 28 53
111 }
112 else {
113 75 return;
114 }
115 }
116  
117 97 ▶sub comment {
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
118 97 my ( $self, $new ) = @_;
119 97 my $old = $self->{comment};
120 97 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 96 97
121 1 $self->{comment} = $new;
122 }
123 97 return $old;
124 }
125  
126 60 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
127 60 my ( $self, $new ) = @_;
128  
129 60 my $name = $Archive::Har::Entry::Cookie::AUTOLOAD;
130 60 $name =~ s/.*://smx; # strip fully-qualified portion
131  
132 60 my $old;
133 60 ▶ if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^_[[:alnum:]]+$/msx) { } 4 56 60
elsif ($name eq 'DESTROY') { } 55 1 56
134 4 $old = $self->{$name};
135 4 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 1 4
136 3 $self->{$name} = $new;
137 }
138 }
139 elsif ( $name eq 'DESTROY' ) {
140 }
141 else {
142 1 Carp::croak(
143 "$name is not specified in the HAR 1.2 spec and does not start with an underscore"
144 );
145 }
146 59 return $old;
147 }
148  
149 74 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=12 SCAR=24.8
Pod undocumented
150 74 my ($self) = @_;
151 74 my $json = {};
152 74 $json->{name} = $self->name();
153 74 $json->{value} = $self->value();
154 74 ▶ if ( defined $self->path() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->path) 21 53 74
155 21 $json->{path} = $self->path();
156 }
157 74 ▶ if ( defined $self->domain() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->domain) 19 55 74
158 19 $json->{domain} = $self->domain();
159 }
160 74 ▶ if ( defined $self->expires() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->expires) 15 59 74
161 15 $json->{expires} = $self->expires();
162 }
163 74 ▶ if ( defined $self->http_only() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->http_only) 28 46 74
164 28 ▶ $json->{httpOnly} = $self->http_only() ? JSON::true() : JSON::false();
Branch: 1 branch
BranchTrueFalseTotal
$self->http_only ? : 15 13 28
165 }
166 74 ▶ if ( defined $self->secure() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->secure) 25 49 74
167 25 ▶ $json->{secure} = $self->secure() ? JSON::true() : JSON::false();
Branch: 1 branch
BranchTrueFalseTotal
$self->secure ? : 12 13 25
168 }
169 74 ▶ if ( defined $self->comment() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 22 52 74
170 22 $json->{comment} = $self->comment();
171 }
172 74 foreach my $key ( sort { $a cmp $b } keys %{$self} ) {
173 300 ▶ next if ( !defined $self->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 45 255 300
174 255 ▶ if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^_[[:alnum:]]+$/msx) 21 234 255
175 21 $json->{$key} = $self->{$key};
176 }
177 }
178 74 return $json;
179 }
180  
181 10 1;
182 __END__
« Har.pm ↑ Summary Har/Entry/Timings.pm »