123 | 123 |
* secure -- if present, the cookie was set C<Secure>
|
124 | 124 |
* httponly -- if present, the cookie was set C<HttpOnly>
|
125 | 125 |
* hostonly -- if present, the cookie may only be used with the domain as a host
|
126 | |
* creation_time -- epoch seconds since the cookie was first stored
|
127 | |
* last_access_time -- epoch seconds since the cookie was last stored
|
|
126 |
* creation_time -- epoch time when the cookie was first stored
|
|
127 |
* last_access_time -- epoch time when the cookie was last accessed (i.e. "now")
|
128 | 128 |
|
129 | 129 |
Keep in mind that C<httponly> means it should only be used in requests and not
|
130 | 130 |
made available via Javascript, etc. This is pretty meaningless for Perl user
|
|
137 | 137 |
=cut
|
138 | 138 |
|
139 | 139 |
sub cookies_for {
|
|
140 |
my ( $self, $request ) = @_;
|
|
141 |
my @found = $self->_cookies_for($request);
|
|
142 |
return map { {%$_} } @found;
|
|
143 |
}
|
|
144 |
|
|
145 |
# _cookies_for returns originals, not copies, which helps in testing
|
|
146 |
sub _cookies_for {
|
140 | 147 |
my ( $self, $request ) = @_;
|
141 | 148 |
my ( $scheme, $host, $port, $request_path ) = eval { _split_url($request) };
|
142 | 149 |
Carp::croak($@) if $@;
|
|
149 | 156 |
next if defined( $cookie->{expires} ) && $cookie->{expires} < $now;
|
150 | 157 |
next unless _domain_match( $host, $cookie->{domain} );
|
151 | 158 |
next unless _path_match( $request_path, $cookie->{path} );
|
|
159 |
$cookie->{last_access_time} = time;
|
152 | 160 |
push @found, $cookie;
|
153 | 161 |
}
|
154 | 162 |
@found = sort {
|
|
255 | 263 |
# private methods
|
256 | 264 |
#--------------------------------------------------------------------------#
|
257 | 265 |
|
258 | |
# return a copy of all cookies
|
|
266 |
# return flattened list of all cookies
|
259 | 267 |
sub _all_cookies {
|
260 | |
return map {
|
261 | |
{ %$_ }
|
262 | |
} map { values %$_ } map { values %$_ } values %{ $_[0]->{store} };
|
|
268 |
return map { values %$_ } map { values %$_ } values %{ $_[0]->{store} };
|
263 | 269 |
}
|
264 | 270 |
|
265 | 271 |
#--------------------------------------------------------------------------#
|