HTTP::CookieMonster::Cookie(3pm) | User Contributed Perl Documentation | HTTP::CookieMonster::Cookie(3pm) |
HTTP::CookieMonster::Cookie - Cookie representation used by HTTP::CookieMonster
version 0.11
use HTTP::CookieMonster::Cookie; my $cookie = HTTP::CookieMonster::Cookie->new( key => 'cookie-name', val => 'cookie-val', path => '/', domain => '.somedomain.org', path_spec => 1, secure => 0, expires => 1376081877 ); use WWW::Mechanize; use HTTP::CookieMonster; my $mech = WWW::Mechanize->new; my $monster = HTTP::CookieMonster->new( cookie_jar => $mech->cookie_jar ); $monster->set_cookie( $cookie ); $mech->get('https://example.com'); # passes $cookie in request
This module is intended to be used by HTTP::CookieMonster to represent cookies found in an HTTP::Cookies cookie_jar. To keep things familiar, I have chosen method names which reflect the positional parameter names laid out in the $cookie_jar->scan( \&callback ) documentation.
Not being intimately familiar with the HTTP cookie spec, I haven't forced validation or default values on any attributes, so please be aware that the burden is on the user to provide "correct" data if you are using this module directly.
I have provided some sample values below. To get a better idea of what is required, try visiting a few sites and dumping their cookies.
use Data::Printer; my $mech = WWW::Mechanize->new; $mech->get( 'http://www.google.ca' ); my $monster = HTTP::CookieMonster->new( cookie_jar => $mech->cookie_jar ); p $monster->all_cookies;
$cookie->version( 0 );
The name of the cookie.
$cookie->key( "session_id" );
The value of the cookie.
$cookie->val( "random_stuff" );
If you are creating a new cookie, you should escape the value first.
use URI::Escape qw( uri_escape ); $cookie->value( uri_escape( 'random_stuff' ) );
$cookie->path( "/" );
$cookie->domain( ".google.ca" );
$cookie->path_spec( 1 );
$cookie->secure( 1 );
$cookie->expires( 1407696193 );
$cookie->hash( { HttpOnly => undef } );
This is mainly useful for creating cookies to be used by LWP::UserAgent and WWW::Mechanize classes. If you need to create cookies to set via headers, have a look at Cookie::Baker.
Olaf Alders <olaf@wundercounter.com>
This software is copyright (c) 2012 by Olaf Alders.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2022-10-14 | perl v5.34.0 |