The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenInteract2::Cookie - Generic cookie methods

SYNOPSIS

 # Create cookies from the request
 
 my $cookies = OpenInteract2::Cookie->parse( $request->cookie_header );
 
 # Create a new cookie and add it to the response manually
 
 my $cookie = OpenInteract2::Cookie->create({
     name    => 'session_id',
     value   => $session->id,
     expires => '+3M'
 });
 $response->add_cookie( $cookie );
 
 # Create the cookie and add it to the response automatically
 
 OpenInteract2::Cookie->create({
     name    => 'session_id',
     value   => $session->id,
     expires => '+3M',
     HEADER  => 'yes',
 });
 
 # Expire a cookie named 'comment_memory'
 
 if ( $forget_info ) {
     OpenInteract2::Cookie->expire( 'comment_memory' );
 }

DESCRIPTION

This module defines methods for parsing and creating cookies. If you do not know what a cookie is, check out:

 http://www.ics.uci.edu/pub/ietf/http/rfc2109.txt

Behind the scenes we use CGI::Cookie to do the actual work. We just take all the credit.

METHODS

All methods are class methods.

parse( $header )

Parses $header into a series of CGI::Cookie objects, which are returned in a hashref with the cookie names as keys and the objects as values.

create( \%params )

Creates a CGI::Cookie object with the given parameters, modified slightly to fit our naming conventions. Additionally, you can add the cookie directly to the response header by passing a true value for the parameter 'HEADER'.

Parameters:

name

Name of the cookie.

value

Value of the cookie.

expires

Expiration date for cookie. This can be a relative date (e.g., '+3M' for three months from now) or an absolute one. See CGI for details about the formats.

path

Path for the cookie. The brower will only pass it back if the URL matches all or part of the path.

XXX: Maybe allow relative paths, or by default stick app context at the front?

If true the cookie will be inserted (via add_cookie()) into the outbound response automatically. Otherwise you need to do so manually.

TODO: should this be the default?

expire( $cookie_name )

Expire the cookie with the given name. We currently do this by creating another cookie with an expiration date three months in the past and issuing it to the response header. This should tell the browser to clear out any cookies under this name.

SEE ALSO

CGI::Cookie

COPYRIGHT

Copyright (c) 2002-2004 Chris Winters. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Chris Winters <chris@cwinters.com>