OpenInteract2::Cookie - Generic cookie methods
# 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' ); }
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.
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.
$header
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 of the cookie.
Value of the cookie.
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 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.
add_cookie()
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.
CGI::Cookie
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.
Chris Winters <chris@cwinters.com>
To install OpenInteract2::URL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenInteract2::URL
CPAN shell
perl -MCPAN -e shell install OpenInteract2::URL
For more information on module installation, please visit the detailed CPAN module installation guide.