CGI-CookieSerial
view release on metacpan or search on metacpan
Revision history for Perl extension CGI::CookieSerial.
0.06 Wed Jan 15 15:53:24 2003
- fixed bug in cool() sub for undefined cookie value
0.05 Wed Jan 15 12:51:03 2003
- made usable with perl 5.6 and above
0.04 Tue Jan 14 15:47 19 2003
- updated the Makefile.PL to check for module dependancies during make/test/install
0.03 Tue Jan 14 14:43:17 2003
- added another example to DESCRIPTION
0.02 Tue Jan 14 14:28:32 2003
- changes made so that non-serialized cookies are also retreivable
0.01 Mon Jan 13 12:32:59 2003
- original version; created by h2xs 1.22 with options
-X -n CGI::CookieSerial
CookieSerial.mfo view on Meta::CPAN
<?xml version="1.0"?>
<modinfo>
<modules>
<module name="CGI::CookieSerial" short_description="a wrapper for creating serialized cookies with Data::Serializer and CGI::Cookie" version="0.06">
<functions/>
<methods>
<method name="burn"/>
<method name="cool"/>
<method name="eat"/>
</methods>
<constructors>
<constructor name="new" short_description="create a new CookieSerial object"/>
</constructors>
<properties/>
<parent_classes/>
<dependencies>
<dependency type="module" target="5.008"/>
<dependency type="module" target="warnings"/>
<dependency type="module" target="CGI::Cookie"/>
<dependency type="module" target="Data::Serializer"/>
</dependencies>
</module>
</modules>
</modinfo>
CookieSerial.pm view on Meta::CPAN
# MODINFO module CGI::CookieSerial a wrapper for creating serialized cookies with Data::Serializer and CGI::Cookie
package CGI::CookieSerial;
# MODINFO dependency module 5.006
use 5.006;
# MODINFO dependency module warnings
use warnings;
# MODINFO dependency module CGI::Cookie
use CGI::Cookie;
# MODINFO dependency module Data::Serializer
use Data::Serializer;
# MODINFO version 0.06
our $VERSION = '0.06';
# MODINFO constructor new create a new CookieSerial object
sub new {
my $class = shift;
$class = ref($class) if ref($class);
my $self = bless {}, $class;
my %flags = @_;
# cookie vars
$self->{name} = $flags{-name} || '';
$self->{data} = $flags{-data} || '';
$self->{path} = $flags{-path} || '/';
CookieSerial.pm view on Meta::CPAN
# MODINFO method burn
sub burn {
my $self = shift;
$self->{data} ||= shift || '';
if ( ! $self->{noserialize} ) {
$self->{data} = $self->{capncrunch}->freeze($self->{data});
}
# make into cookie form
my $cookie = CGI::Cookie->new(
-name => $self->{name},
-value => $self->{data},
-path => $self->{path},
-domain => $self->{domain},
-secure => $self->{secure},
-expires => $self->{expires},
);
# print header
print "Set-Cookie: $cookie\n";
}
# MODINFO method cool
sub cool {
my $self = shift;
# fetch cookie
my %cookies = fetch CGI::Cookie;
$self->{data} ||= '';
$self->{debug} = "\$self->{data} = $self->{data}<br>".
"\$self->{name} = $self->{name}<br>";
my $data = $cookies{$self->{name}}->value() if $self->{data};
# deserialize the data
my $soggy = ( $self->{noserialize} ) ? $data : $self->{capncrunch}->thaw($data);
return $soggy;
}
CookieSerial.pm view on Meta::CPAN
my $cookie_name = shift;
print $self->cool($cookie_name);
}
1;
__END__
=head1 NAME
CGI::CookieSerial - a wrapper for creating a CGI serial cookie or cookies with any serialized perl data stuctures
=head1 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,
},
CookieSerial.pm view on Meta::CPAN
$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>";
=head1 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.
=head1 DESCRIPTION
This module is simpler to use than other cookie modules, but other than that, there isn't much difference.
=head1 METHONDS
=head2 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 ...
-name
-value
-expires
-domain
-path
-secure
and
CookieSerial.pm view on Meta::CPAN
Implement this with inheritance
=item
Not require that data be a reference, and have the module intelligently check and then Do The Right Thing
=back
=head1 SEE ALSO
L<CGI>, L<CGI::Cookie>, L<Data::Serializer>
=head1 AUTHOR
Duncan McGreggor, E<lt>oubiwann at cpan dot orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2003 by Duncan McGreggor
This library is free software; you can redistribute it and/or modify
Changes
CookieSerial.pm
CookieSerial.mfo
Makefile.PL
MANIFEST
README
t/1.t
Makefile.PL view on Meta::CPAN
# the above handlers must be declared before the 'use' statement
use ExtUtils::AutoInstall (
-version => '0.40', # required AutoInstall version
# usually 0.40 is sufficient
-config => {
make_args => '--hello', # option(s) for CPAN::Config
force => 1, # pseudo-option to force install
},
'Required modules' => [
'CGI' => '2.89',
'CGI::Cookie' => '1.21',
'Data::Serializer' => '0.17',
],
);
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'CGI::CookieSerial',
'VERSION_FROM' => 'CookieSerial.pm', # finds $VERSION
'PREREQ_PM' => {
'CGI' => '2.89',
'CGI::Cookie' => '1.21',
'Data::Serializer' => '0.17',
}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'CookieSerial.pm', # retrieve abstract from module
AUTHOR => 'Duncan McGreggor <oubiwann@cpan.org>') : ()),
);
CGI/CookieSerial version 0.01
=============================
Check the SYNOPSIS and DESCRIPTION of the POD for the latest
documentation and intro to this module.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
CGI::Cookie
Data::Serializer
COPYRIGHT AND LICENCE
Copyright (C) 2003 Duncan McGreggor
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('CGI::CookieSerial') };
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
( run in 1.900 second using v1.01-cache-2.11-cpan-e9199f4ba4c )