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