App-Context
view release on metacpan or search on metacpan
lib/App/Session/Cookie.pm view on Meta::CPAN
}
#############################################################################
# PROTECTED METHODS
#############################################################################
=head1 Protected Methods:
The following methods are intended to be called by subclasses of the
current class.
=cut
#############################################################################
# create()
#############################################################################
=head2 create()
The create() method is used to create the Perl structure that will
be blessed into the class and returned by the constructor.
* Signature: $ref = App::Reference->create($hashref)
* Param: $hashref {}
* Return: $ref ref
* Throws: App::Exception
* Since: 0.01
Sample Usage:
=cut
sub create {
my ($self, $args) = @_;
$args = {} if (!defined $args);
my ($ref);
$ref = {};
$ref;
}
#############################################################################
# _init()
#############################################################################
=head2 _init()
The _init() method is called from within the constructor.
* Signature: _init($named)
* Param: $named {} [in]
* Return: void
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$ref->_init($args);
The _init() method looks at the cookies in the request
and restores the session state information from the cookies
named "app_sessiondata" (and "app_sessiondata[2..n]").
When the values of these cookies are concatenated, they
form a Base64-encoded, gzipped, frozen multi-level hash of
session state data. To retrieve the state data, the text
is therefore decoded, gunzipped, and thawed (a la Storable).
Notes on length of cookies: See
http://developer.netscape.com/docs/manuals/js/client/jsref/cookies.htm
An excerpt is included here.
The Navigator can receive and store the following:
* 300 total cookies
* 4 kilobytes per cookie, where the name and the OPAQUE_STRING
combine to form the 4 kilobyte limit.
* 20 cookies per server or domain. Completely specified hosts
and domains are considered separate entities, and each has
a 20 cookie limitation.
When the 300 cookie limit or the 20 cookie per server limit is exceeded,
Navigator deletes the least recently used cookie. When a cookie larger
than 4 kilobytes is encountered the cookie should be trimmed to fit,
but the name should remain intact as long as it is less than 4 kilobytes.
TODO: encrypt and MAC
=cut
sub _init {
my ($self, $args) = @_;
my ($cgi, $sessiontext, $store, $length, $pad);
my $context = $self->{context} = $args->{context};
$store = {};
$cgi = $args->{cgi} if (defined $args);
if (! defined $cgi && $context->can("request")) {
$cgi = $context->request()->{cgi};
}
if (defined $cgi) {
$sessiontext = $cgi->cookie("app_sessiondata");
if ($sessiontext) {
my ($i, $textchunk);
$i = 2;
while (1) {
$textchunk = $cgi->cookie("app_sessiondata${i}");
last if (!$textchunk);
$sessiontext .= $textchunk;
$i++;
}
$sessiontext =~ s/ /\+/g;
$length = length($sessiontext);
$pad = 4 - ($length % 4);
$pad = 0 if ($pad == 4);
$sessiontext .= ("=" x $pad) if ($pad);
#print "length(sessiontext)=", length($sessiontext), "\n";
$sessiontext =~ s/(.{76})/$1\n/g;
( run in 2.071 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )