Apache2-WebApp-Plugin-Session
view release on metacpan or search on metacpan
lib/Apache2/WebApp/Plugin/Session.pm view on Meta::CPAN
# Return session data as a hash reference.
sub get {
my $self = shift;
$self->_init_new($_[0]);
$self->{OBJECT}->get(@_);
}
#----------------------------------------------------------------------------+
# delete(\%controller, $name)
#
# Delete an existing session.
sub delete {
my $self = shift;
$self->_init_new($_[0]);
$self->{OBJECT}->delete(@_);
}
#----------------------------------------------------------------------------+
# update(\%controller, $name, \%data)
#
# Update existing session data.
sub update {
my $self = shift;
$self->_init_new($_[0]);
$self->{OBJECT}->update(@_);
}
#----------------------------------------------------------------------------+
# id(\%controller, $name)
#
# Return the unique identifier for the given session.
sub id {
my $self = shift;
$self->_init_new($_[0]);
$self->{OBJECT}->id(@_);
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~[ PRIVATE METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#----------------------------------------------------------------------------+
# _init(\%params)
#
# Return a reference of $self to the caller.
sub _init {
my ($self, $params) = @_;
return $self;
}
#----------------------------------------------------------------------------+
# _init_new(\%controller)
#
# Based on config value for 'storage_type', include the correct sub-class.
sub _init_new {
my ($self, $c)
= validate_pos(@_,
{ type => OBJECT },
{ type => HASHREF }
);
my $package;
switch ($c->config->{session_storage_type}) {
case /file/ { $package = "Apache2::WebApp::Plugin::Session::File" }
case /memcached/ { $package = "Apache2::WebApp::Plugin::Session::Memcached" }
case /mysql/ { $package = "Apache2::WebApp::Plugin::Session::MySQL" }
else {
$self->error("Missing config value for 'storage_type'");
}
}
unless ( $package->can('isa') ) {
eval "require $package";
$self->error("Failed to load package '$package': $@") if $@;
}
if ( $package->can('new') ) {
$self->{OBJECT} = $package->new;
}
return $self;
}
1;
__END__
=head1 NAME
Apache2::WebApp::Plugin::Session - Plugin providing session handling methods
=head1 SYNOPSIS
my $obj = $c->plugin('Session')->method( ... ); # Apache2::WebApp::Plugin::Session->method()
or
$c->plugin('Session')->method( ... );
=head1 DESCRIPTION
An abstract class that provides common methods for managing session data
across servers, within a database, or local file. Data persistence is
maintained between requests using web browser cookies.
=head1 PREREQUISITES
This package is part of a larger distribution and was NOT intended to be used
directly. In order for this plugin to work properly, the following packages
must be installed:
Apache2::WebApp
Apache2::WebApp::Plugin::Cookie
Apache::Session
Params::Validate
( run in 2.707 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )