HTTP::CookieMonster::Cookie(3)

NAME
HTTP::CookieMonster::Cookie - Cookie representation used by HTTP::CookieMonster

VERSION
version 0.11

SYNOPSIS
    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

DESCRIPTION
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;

  version
    $cookie->version( 0 );

  key
The name of the cookie.

    $cookie->key( "session_id" );

  val
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' ) );

  path
    $cookie->path( "/" );

  domain
    $cookie->domain( ".google.ca" );

  port

  path_spec
    $cookie->path_spec( 1 );

  secure
    $cookie->secure( 1 );

  expires
    $cookie->expires( 1407696193 );

  discard

  hash
    $cookie->hash( { HttpOnly => undef } );

SEE ALSO
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.

AUTHOR
Olaf Alders <olaf@wundercounter.com>

COPYRIGHT AND LICENSE
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.