Har/Entry/Cache/Request.pm

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