line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::CookieMonster; |
2
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
3
|
2
|
|
|
2
|
|
1000
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
45
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1058
|
use Moo 1.000003; |
|
2
|
|
|
|
|
25177
|
|
|
2
|
|
|
|
|
11
|
|
9
|
2
|
|
|
2
|
|
2953
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
90
|
|
10
|
2
|
|
|
2
|
|
1002
|
use HTTP::Cookies; |
|
2
|
|
|
|
|
27829
|
|
|
2
|
|
|
|
|
66
|
|
11
|
2
|
|
|
2
|
|
805
|
use HTTP::CookieMonster::Cookie; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
65
|
|
12
|
2
|
|
|
2
|
|
926
|
use Safe::Isa; |
|
2
|
|
|
|
|
960
|
|
|
2
|
|
|
|
|
285
|
|
13
|
2
|
|
|
2
|
|
15
|
use Scalar::Util qw( reftype ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
102
|
|
14
|
2
|
|
|
2
|
|
1045
|
use Sub::Exporter -setup => { exports => ['cookies'] }; |
|
2
|
|
|
|
|
19925
|
|
|
2
|
|
|
|
|
12
|
|
15
|
2
|
|
|
2
|
|
1625
|
use URI::Escape qw( uri_escape uri_unescape ); |
|
2
|
|
|
|
|
2928
|
|
|
2
|
|
|
|
|
1459
|
|
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
|
4465
|
my ( $class, @args ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
8
|
100
|
|
|
|
136
|
return { cookie_jar => shift @args } if @args == 1; |
31
|
1
|
|
|
|
|
18
|
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
|
851
|
my $self = shift; |
42
|
13
|
|
|
|
|
58
|
@_cookies = (); |
43
|
13
|
|
|
|
|
63
|
$self->cookie_jar->scan( \&_check_cookies ); |
44
|
|
|
|
|
|
|
|
45
|
13
|
100
|
|
|
|
83
|
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
|
2199
|
my ( $cookie_jar, $name ) = @_; |
55
|
5
|
50
|
|
|
|
18
|
croak 'This function is not part of the OO interface' |
56
|
|
|
|
|
|
|
if $cookie_jar->$_isa('HTTP::CookieMonster'); |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
190
|
my $monster = HTTP::CookieMonster->new($cookie_jar); |
59
|
|
|
|
|
|
|
|
60
|
5
|
100
|
|
|
|
180
|
if ( !$name ) { |
61
|
2
|
100
|
|
|
|
6
|
if ( !wantarray ) { |
62
|
1
|
|
|
|
|
173
|
croak |
63
|
|
|
|
|
|
|
'Please specify a cookie name when asking for a single cookie'; |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
2
|
return @{ $monster->all_cookies }; |
|
1
|
|
|
|
|
2
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
8
|
return $monster->get_cookie($name); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_cookie { |
72
|
8
|
|
|
8
|
1
|
428
|
my $self = shift; |
73
|
8
|
|
|
|
|
12
|
my $name = shift; |
74
|
|
|
|
|
|
|
|
75
|
8
|
|
|
|
|
15
|
my @cookies = (); |
76
|
8
|
|
|
|
|
389
|
foreach my $cookie ( $self->all_cookies ) { |
77
|
16
|
100
|
|
|
|
51
|
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
|
|
|
|
14
|
return shift @cookies if !wantarray; |
84
|
4
|
|
|
|
|
18
|
return @cookies; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub set_cookie { |
88
|
6
|
|
|
6
|
1
|
274
|
my $self = shift; |
89
|
6
|
|
|
|
|
12
|
my $cookie = shift; |
90
|
|
|
|
|
|
|
|
91
|
6
|
100
|
|
|
|
15
|
if ( !$cookie ) { |
92
|
1
|
|
|
|
|
94
|
croak 'Missing cookie, an HTTP::CookieMonster::Cookie object'; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
5
|
50
|
|
|
|
20
|
if ( !$cookie->$_isa('HTTP::CookieMonster::Cookie') ) { |
96
|
0
|
|
|
|
|
0
|
croak "$cookie is not a HTTP::CookieMonster::Cookie object"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
5
|
50
|
|
|
|
108
|
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
|
548
|
my $self = shift; |
111
|
1
|
|
|
|
|
3
|
my $cookie = shift; |
112
|
|
|
|
|
|
|
|
113
|
1
|
50
|
|
|
|
4
|
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
|
32
|
|
|
32
|
|
548
|
my @args = @_; |
124
|
|
|
|
|
|
|
|
125
|
32
|
|
|
|
|
110
|
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
|
32
|
|
|
|
|
5298
|
return; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# ABSTRACT: Easy read/write access to your jar of HTTP::Cookies |
146
|
|
|
|
|
|
|
# |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |