| Apache2-WebApp-Plugin-Session documentation | view source | Contained in the Apache2-WebApp-Plugin-Session distribution. |
Apache2::WebApp::Plugin::Session - Plugin providing session handling methods
my $obj = $c->plugin('Session')->method( ... ); # Apache2::WebApp::Plugin::Session->method()
or
$c->plugin('Session')->method( ... );
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.
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 Switch
From source:
$ tar xfz Apache2-WebApp-Plugin-Session-0.X.X.tar.gz $ perl MakeFile.PL PREFIX=~/path/to/custom/dir LIB=~/path/to/custom/lib $ make $ make test $ make install
Perl one liner using CPAN.pm:
$ perl -MCPAN -e 'install Apache2::WebApp::Plugin::Session'
Use of CPAN.pm in interactive mode:
$ perl -MCPAN -e shell cpan> install Apache2::WebApp::Plugin::Session cpan> quit
Just like the manual installation of Perl modules, the user may need root access during this process to insure write permission is allowed within the installation directory.
Unless it already exists, add the following to your projects webapp.conf
[session] storage_type = file # options - file | mysql | memcached expires = 1h # default 24h
Create a new session.
By default, when a new session is created, a browser cookie is set that contains
a session_id. Upon success, this session identifier is returned, which can
also be used to set a customized session cookie.
my $session_id = $c->plugin('Session')->create( $c, 'login',
{
username => 'foo',
password => 'bar',
}
);
Takes the cookie unique identifier or session id as arguments. Returns the session data as a hash reference.
my $data_ref = $c->plugin('Session')->get( $c, 'login' );
print $data_ref->{username}; # outputs 'foo'
Takes the cookie unique identifier or session id as arguments. Updates existing session data.
$c->plugin('Session')->update( $c, 'login',
{
last_login => localtime(time),
remember => 1,
}
);
Takes the cookie unique identifier or session id as arguments. Deletes an existing session.
$c->plugin('Session')->delete( $c, 'login' );
Return the cookie unique identifier for a given session.
my $session_id = $c->plugin('Session')->id( $c, 'login' );
package Example;
sub _default {
my ( $self, $c ) = @_;
$c->plugin('Session')->create( $c, 'login',
{
username => 'foo',
password => 'bar',
}
);
$c->plugin('CGI')->redirect( $c, '/app/example/verify' );
}
sub verify {
my ( $self, $c ) = @_;
my $data_ref = $c->plugin('Session')->get( $c, 'login' );
$c->request->content_type('text/html');
print $data_ref->{username} . ' - ' . $data_ref->{password}; # outputs 'foo-bar'
}
1;
Marc S. Brooks, <mbrooks@cpan.org> - http://mbrooks.info
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Apache2-WebApp-Plugin-Session documentation | view source | Contained in the Apache2-WebApp-Plugin-Session distribution. |