line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Archive::Har::Entry::Cache::Request; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1041
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
1
|
|
my ( $class, $params ) = @_; |
11
|
0
|
|
|
|
|
|
my $self = {}; |
12
|
0
|
|
|
|
|
|
bless $self, $class; |
13
|
0
|
0
|
|
|
|
|
if ( defined $params ) { |
14
|
0
|
0
|
|
|
|
|
if ( defined $params->{expires} ) { |
15
|
0
|
|
|
|
|
|
$self->expires( $params->{expires} ); |
16
|
|
|
|
|
|
|
} |
17
|
0
|
|
|
|
|
|
$self->last_access( $params->{lastAccess} ); |
18
|
0
|
|
|
|
|
|
$self->etag( $params->{eTag} ); |
19
|
0
|
|
|
|
|
|
$self->hit_count( $params->{hitCount} ); |
20
|
0
|
0
|
|
|
|
|
if ( defined $params->{comment} ) { |
21
|
0
|
|
|
|
|
|
$self->comment( $params->{comment} ); |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
foreach my $key ( sort { $a cmp $b } keys %{$params} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields |
25
|
0
|
|
|
|
|
|
$self->$key( $params->{$key} ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub expires { |
33
|
0
|
|
|
0
|
1
|
|
my ( $self, $new ) = @_; |
34
|
0
|
|
|
|
|
|
my $old = $self->{expires}; |
35
|
0
|
0
|
|
|
|
|
if ( @_ > 1 ) { |
36
|
0
|
|
|
|
|
|
$self->{expires} = $new; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
return $old; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub last_access { |
42
|
0
|
|
|
0
|
1
|
|
my ( $self, $new ) = @_; |
43
|
0
|
|
|
|
|
|
my $old = $self->{lastAccess}; |
44
|
0
|
0
|
|
|
|
|
if ( @_ > 1 ) { |
45
|
0
|
0
|
|
|
|
|
if ( defined $new ) { |
46
|
0
|
|
|
|
|
|
my $date_regex = qr/\d{4}[-]\d{2}[-]\d{2}/smx; |
47
|
0
|
|
|
|
|
|
my $time_regex = qr/\d{2}:\d{2}:\d{2}[.]\d+/smx; |
48
|
0
|
|
|
|
|
|
my $zone_regex = qr/(?:[+]\d{2}:\d{2}|Z)/smx; |
49
|
0
|
0
|
|
|
|
|
if ( $new =~ /^${date_regex}T${time_regex}${zone_regex}$/smx ) { |
50
|
0
|
|
|
|
|
|
$self->{lastAccess} = $new; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
0
|
|
|
|
|
|
Carp::croak('last_access is not formatted correctly'); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
0
|
|
|
|
|
|
$self->{lastAccess} = '0000-00-00T00-00-00'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
0
|
|
|
|
if ( ( defined $old ) && ( $old eq '0000-00-00T00-00-00' ) ) { |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
|
return $old; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub etag { |
69
|
0
|
|
|
0
|
1
|
|
my ( $self, $new ) = @_; |
70
|
0
|
|
|
|
|
|
my $old = $self->{eTag}; |
71
|
0
|
0
|
|
|
|
|
if ( @_ > 1 ) { |
72
|
0
|
|
|
|
|
|
$self->{eTag} = $new; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
0
|
|
|
|
|
if ( defined $old ) { |
75
|
0
|
|
|
|
|
|
return $old; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
|
return q[]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub hit_count { |
83
|
0
|
|
|
0
|
0
|
|
my ( $self, $new ) = @_; |
84
|
0
|
|
|
|
|
|
my $old = $self->{hitCount}; |
85
|
0
|
0
|
|
|
|
|
if ( @_ > 1 ) { |
86
|
0
|
|
|
|
|
|
$self->{hitCount} = $new; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
0
|
|
|
|
|
if ( defined $old ) { |
89
|
0
|
|
|
|
|
|
return $old; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
0
|
|
|
|
|
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub comment { |
97
|
0
|
|
|
0
|
1
|
|
my ( $self, $new ) = @_; |
98
|
0
|
|
|
|
|
|
my $old = $self->{comment}; |
99
|
0
|
0
|
|
|
|
|
if ( @_ > 1 ) { |
100
|
0
|
|
|
|
|
|
$self->{comment} = $new; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
return $old; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub AUTOLOAD { |
106
|
0
|
|
|
0
|
|
|
my ( $self, $new ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $name = $Archive::Har::Entry::Cache::Request::AUTOLOAD; |
109
|
0
|
|
|
|
|
|
$name =~ s/.*://smx; # strip fully-qualified portion |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $old; |
112
|
0
|
0
|
|
|
|
|
if ( $name =~ /^_[[:alnum:]]+$/smx ) { # private fields |
|
|
0
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$old = $self->{$name}; |
114
|
0
|
0
|
|
|
|
|
if ( @_ > 1 ) { |
115
|
0
|
|
|
|
|
|
$self->{$name} = $new; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif ( $name eq 'DESTROY' ) { |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
0
|
|
|
|
|
|
Carp::croak( |
122
|
|
|
|
|
|
|
"$name is not specified in the HAR 1.2 spec and does not start with an underscore" |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
return $old; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub TO_JSON { |
129
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
130
|
0
|
|
|
|
|
|
my $json = {}; |
131
|
0
|
0
|
|
|
|
|
if ( defined $self->expires() ) { |
132
|
0
|
|
|
|
|
|
$json->{expires} = $self->expires(); |
133
|
|
|
|
|
|
|
} |
134
|
0
|
0
|
|
|
|
|
if ( $self->last_access() ) { |
135
|
0
|
|
|
|
|
|
$json->{lastAccess} = $self->last_access(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
0
|
|
|
|
|
|
$json->{lastAccess} = '0000-00-00T00-00-00'; |
139
|
|
|
|
|
|
|
} |
140
|
0
|
|
|
|
|
|
$json->{eTag} = $self->etag(); |
141
|
0
|
|
|
|
|
|
$json->{hitCount} = $self->hit_count(); |
142
|
0
|
0
|
|
|
|
|
if ( defined $self->comment() ) { |
143
|
0
|
|
|
|
|
|
$json->{comment} = $self->comment(); |
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
|
foreach my $key ( sort { $a cmp $b } keys %{$self} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
next if ( !defined $self->{$key} ); |
147
|
0
|
0
|
|
|
|
|
if ( $key =~ /^_[[:alnum:]]+$/smx ) { # private fields |
148
|
0
|
|
|
|
|
|
$json->{$key} = $self->{$key}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
return $json; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
155
|
|
|
|
|
|
|
__END__ |