NAME
CGI::CookieSerial - a wrapper for creating a CGI serial cookie or cookies with any serialized perl data stuctures
SYNOPSIS
Setting a cookie with data:
use strict;
use CGI;
use CGI::CookieSerial;
my $cgi = new CGI;
my $pbscookie = new CGI::CookieSerial(
-name => 'ticklemeelmo',
);
my @data = (
{
'to' => 'di',
'froo' => 'ti',
actor => 'Steve Martin',
food => 3.14,
},
'apple',
24,
);
$pbscookie->burn(\@data);
print $cgi->header({
-type => 'text/html',
});
Retrieving a cookie with data:
use strict;
use Data::Dumper;
use CGI;
use CGI::CookieSerial;
my $cgi = new CGI;
my $pbscookie = new CGI::CookieSerial(
-name => 'ticklemeelmo',
);
my @data = @{$pbscookie->cool()};
print $cgi->header({ -type => 'text/html', });
print "<html><body><pre>Data check:<br>";
print Dumper(@data)."<br>";
print "$data[2]<br>";
print "$data[0]{actor}";
print "</body></html>";
Retrieving a regular cookie:
use strict;
use Data::Dumper;
use CGI;
use CGI::CookieSerial;
my $cgi = new CGI;
my $pbscookie = new CGI::CookieSerial(
-name => 'tv.station',
-noserialize => 1,
);
my $station_call_letters = $pbscookie->cool();
print $cgi->header({ -type => 'text/html', });
print "<html><body><pre>";
print "Call letters: $station_call_letters";
print "</body></html>";
ABSTRACT
Although deceptively similar to the workings of CGI::Cookie, this module operates a little differently. By design, it is very simple to use. In essence, one need only instantiate a new object and name the cookie, create the data, and burn the cookie. Retrieval is just as simple.
DESCRIPTION
This module is simpler to use than other cookie modules, but other than that, there isn't much difference.
METHONDS
new()
In addition to the CGI::Cookie->new() parameters, the constructor also takes the same parameters as Data::Serializer->new(). There is one new parameter, -noserialize, which is a boolean that enables one to turn off the serializing function and fetch regular cookies. These give the following list of parameters:
-name
-value
-expires
-domain
-path
-secure
and
-noserialize
and
-serializer
-digester
-cipher
-secret
-portable
-compress
-serializer_token
burn()
This method takes a parameter that is a reference to the data you want to store in the cookie. It serializes it and then sends the header. Only call this method when you are ready to set the cookie header.
cool()
This method returns the value of the cookie, either a stings or a reference (depending on what you stored).
eat()
This method simply prints the value of the cookie. There's really not a great deal of use for this method, despite the name, unless you are debugging.
TODO
Implement this with inheritance
Not require that data be a reference, and have the module intelligently check and then Do The Right Thing
SEE ALSO
CGI, CGI::Cookie, Data::Serializer
AUTHOR
Duncan McGreggor, <oubiwann at cpan dot org>
COPYRIGHT AND LICENSE
Copyright 2003 by Duncan McGreggor
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.