CGI-Application-Plugin-Cache-Adaptive
view release on metacpan or search on metacpan
inc/CGI/Session.pm view on Meta::CPAN
#line 1
package CGI::Session;
# $Id: Session.pm 353 2006-12-05 02:10:19Z markstos $
use strict;
use Carp;
use CGI::Session::ErrorHandler;
@CGI::Session::ISA = qw( CGI::Session::ErrorHandler );
$CGI::Session::VERSION = '4.20';
$CGI::Session::NAME = 'CGISESSID';
$CGI::Session::IP_MATCH = 0;
sub STATUS_NEW () { 1 } # denotes session that's just created
sub STATUS_MODIFIED () { 2 } # denotes session that needs synchronization
sub STATUS_DELETED () { 4 } # denotes session that needs deletion
sub STATUS_EXPIRED () { 8 } # denotes session that was expired.
sub import {
my ($class, @args) = @_;
return unless @args;
ARG:
foreach my $arg (@args) {
if ($arg eq '-ip_match') {
$CGI::Session::IP_MATCH = 1;
last ARG;
}
}
}
sub new {
my ($class, @args) = @_;
my $self;
if (ref $class) {
#
# Called as an object method as in $session->new()...
#
$self = bless { %$class }, ref( $class );
$class = ref $class;
$self->_reset_status();
#
# Object may still have public data associated with it, but we
# don't care about that, since we want to leave that to the
# client's disposal. However, if new() was requested on an
# expired session, we already know that '_DATA' table is
# empty, since it was the job of flush() to empty '_DATA'
# after deleting. How do we know flush() was already called on
# an expired session? Because load() - constructor always
# calls flush() on all to-be expired sessions
#
}
else {
#
# Called as a class method as in CGI::Session->new()
#
$self = $class->load( @args );
if (not defined $self) {
return $class->set_error( "new(): failed: " . $class->errstr );
}
}
my $dataref = $self->{_DATA};
unless ($dataref->{_SESSION_ID}) {
#
# Absence of '_SESSION_ID' can only signal:
# * Expired session: Because load() - constructor is required to
# empty contents of _DATA - table
# * Unavailable session: Such sessions are the ones that don't
# exist on datastore, but are requested by client
# * New session: When no specific session is requested to be loaded
#
my $id = $self->_id_generator()->generate_id(
$self->{_DRIVER_ARGS},
( run in 1.027 second using v1.01-cache-2.11-cpan-39bf76dae61 )