line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::CookieMonster; |
2
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
3
|
2
|
|
|
2
|
|
1030
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
44
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
39
|
use 5.006; |
|
2
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
941
|
use Moo 1.000003; |
|
2
|
|
|
|
|
26944
|
|
|
2
|
|
|
|
|
10
|
|
9
|
2
|
|
|
2
|
|
2692
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
80
|
|
10
|
2
|
|
|
2
|
|
896
|
use HTTP::Cookies; |
|
2
|
|
|
|
|
25325
|
|
|
2
|
|
|
|
|
54
|
|
11
|
2
|
|
|
2
|
|
782
|
use HTTP::CookieMonster::Cookie; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
64
|
|
12
|
2
|
|
|
2
|
|
832
|
use Safe::Isa; |
|
2
|
|
|
|
|
933
|
|
|
2
|
|
|
|
|
270
|
|
13
|
2
|
|
|
2
|
|
15
|
use Scalar::Util qw( reftype ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
97
|
|
14
|
2
|
|
|
2
|
|
974
|
use Sub::Exporter -setup => { exports => ['cookies'] }; |
|
2
|
|
|
|
|
18380
|
|
|
2
|
|
|
|
|
15
|
|
15
|
2
|
|
|
2
|
|
1567
|
use URI::Escape qw( uri_escape uri_unescape ); |
|
2
|
|
|
|
|
2762
|
|
|
2
|
|
|
|
|
1362
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my @_cookies = (); |
18
|
|
|
|
|
|
|
has 'cookie_jar' => ( |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => sub { |
22
|
|
|
|
|
|
|
croak 'HTTP::Cookies object expected' |
23
|
|
|
|
|
|
|
if !$_[0]->$_isa('HTTP::Cookies'); |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub BUILDARGS { |
28
|
8
|
|
|
8
|
0
|
5245
|
my ( $class, @args ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
8
|
100
|
|
|
|
126
|
return { cookie_jar => shift @args } if @args == 1; |
31
|
1
|
|
|
|
|
19
|
return {@args}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# all_cookies() is now a straight method rather than a Moo accessor in order to |
35
|
|
|
|
|
|
|
# prevent the all_cookies list from getting out of sync with changes to the |
36
|
|
|
|
|
|
|
# cookie_jar which happen outside of this module. Rather than trying to detect |
37
|
|
|
|
|
|
|
# changes, we'll just create a fresh list each time. Performance penalties |
38
|
|
|
|
|
|
|
# should be minimal and this keeps things simple. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub all_cookies { |
41
|
13
|
|
|
13
|
1
|
866
|
my $self = shift; |
42
|
13
|
|
|
|
|
76
|
@_cookies = (); |
43
|
13
|
|
|
|
|
59
|
$self->cookie_jar->scan( \&_check_cookies ); |
44
|
|
|
|
|
|
|
|
45
|
13
|
100
|
|
|
|
80
|
wantarray ? return @_cookies : return \@_cookies; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# my $cookie = cookies( $jar ); -- first cookie (makes no sense) |
49
|
|
|
|
|
|
|
# my $session = cookies( $jar, 'session' ); |
50
|
|
|
|
|
|
|
# my @cookies = cookies( $jar ); |
51
|
|
|
|
|
|
|
# my @sessions = cookies( $jar, 'session' ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub cookies { |
54
|
5
|
|
|
5
|
1
|
2779
|
my ( $cookie_jar, $name ) = @_; |
55
|
5
|
50
|
|
|
|
15
|
croak 'This function is not part of the OO interface' |
56
|
|
|
|
|
|
|
if $cookie_jar->$_isa('HTTP::CookieMonster'); |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
158
|
my $monster = HTTP::CookieMonster->new($cookie_jar); |
59
|
|
|
|
|
|
|
|
60
|
5
|
100
|
|
|
|
148
|
if ( !$name ) { |
61
|
2
|
100
|
|
|
|
6
|
if ( !wantarray ) { |
62
|
1
|
|
|
|
|
154
|
croak |
63
|
|
|
|
|
|
|
'Please specify a cookie name when asking for a single cookie'; |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
1
|
return @{ $monster->all_cookies }; |
|
1
|
|
|
|
|
3
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
7
|
return $monster->get_cookie($name); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_cookie { |
72
|
8
|
|
|
8
|
1
|
393
|
my $self = shift; |
73
|
8
|
|
|
|
|
15
|
my $name = shift; |
74
|
|
|
|
|
|
|
|
75
|
8
|
|
|
|
|
13
|
my @cookies = (); |
76
|
8
|
|
|
|
|
17
|
foreach my $cookie ( $self->all_cookies ) { |
77
|
30
|
100
|
|
|
|
69
|
if ( $cookie->key eq $name ) { |
78
|
10
|
100
|
|
|
|
35
|
return $cookie if !wantarray; |
79
|
6
|
|
|
|
|
11
|
push @cookies, $cookie; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
4
|
50
|
|
|
|
13
|
return shift @cookies if !wantarray; |
84
|
4
|
|
|
|
|
18
|
return @cookies; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub set_cookie { |
88
|
6
|
|
|
6
|
1
|
243
|
my $self = shift; |
89
|
6
|
|
|
|
|
9
|
my $cookie = shift; |
90
|
|
|
|
|
|
|
|
91
|
6
|
100
|
|
|
|
45
|
if ( !$cookie ) { |
92
|
1
|
|
|
|
|
75
|
croak 'Missing cookie, an HTTP::CookieMonster::Cookie object'; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
5
|
50
|
|
|
|
24
|
if ( !$cookie->$_isa('HTTP::CookieMonster::Cookie') ) { |
96
|
0
|
|
|
|
|
0
|
croak "$cookie is not a HTTP::CookieMonster::Cookie object"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
5
|
50
|
|
|
|
117
|
return $self->cookie_jar->set_cookie( |
100
|
|
|
|
|
|
|
$cookie->version, $cookie->key, |
101
|
|
|
|
|
|
|
uri_escape( $cookie->val ), $cookie->path, |
102
|
|
|
|
|
|
|
$cookie->domain, $cookie->port, |
103
|
|
|
|
|
|
|
$cookie->path_spec, $cookie->secure, |
104
|
|
|
|
|
|
|
$cookie->expires, $cookie->discard, |
105
|
|
|
|
|
|
|
$cookie->hash |
106
|
|
|
|
|
|
|
) ? 1 : 0; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub delete_cookie { |
110
|
1
|
|
|
1
|
1
|
551
|
my $self = shift; |
111
|
1
|
|
|
|
|
3
|
my $cookie = shift; |
112
|
|
|
|
|
|
|
|
113
|
1
|
50
|
|
|
|
5
|
if ( !$cookie->$_isa('HTTP::CookieMonster::Cookie') ) { |
114
|
0
|
|
|
|
|
0
|
croak "$cookie is not a HTTP::CookieMonster::Cookie object"; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
20
|
$cookie->expires(-1); |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
4
|
return $self->set_cookie($cookie); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _check_cookies { |
123
|
58
|
|
|
58
|
|
813
|
my @args = @_; |
124
|
|
|
|
|
|
|
|
125
|
58
|
|
|
|
|
164
|
push @_cookies, |
126
|
|
|
|
|
|
|
HTTP::CookieMonster::Cookie->new( |
127
|
|
|
|
|
|
|
version => $args[0], |
128
|
|
|
|
|
|
|
key => $args[1], |
129
|
|
|
|
|
|
|
val => uri_unescape( $args[2] ), |
130
|
|
|
|
|
|
|
path => $args[3], |
131
|
|
|
|
|
|
|
domain => $args[4], |
132
|
|
|
|
|
|
|
port => $args[5], |
133
|
|
|
|
|
|
|
path_spec => $args[6], |
134
|
|
|
|
|
|
|
secure => $args[7], |
135
|
|
|
|
|
|
|
expires => $args[8], |
136
|
|
|
|
|
|
|
discard => $args[9], |
137
|
|
|
|
|
|
|
hash => $args[10], |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
|
140
|
58
|
|
|
|
|
6260
|
return; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# ABSTRACT: Easy read/write access to your jar of HTTP::Cookies |
146
|
|
|
|
|
|
|
# |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |