NAME
Object::Generic::Session - a web application session with an interface like Class::DBI.
SYNOPSIS
# This example stores user data in a $session global
# in an HTML::Mason web application framework.
# -- file httpd.conf -- (Define the session global.)
PerlAddVar MasonAllowGlobals $session
# -- file htdocs/autohandler - (Retrieve the session; process webpage.)
% $session = new Object::Session::Generic(
% session_config => { Store=>'MySQL', ... }, # See Session.pm
% cookie_name => 'your cookie name here',
% expires => '+8h',
% );
% $m->call_next;
% $session = undef;
# -- file htdocs/file.html -- (Use the session to access key/value pairs.)
<html>
% if ($session->user){
Hi <% $session->user->name %>. Welcome back.
% } else {
<form>
Please log in: <input type="text" name="username" />
</form>
% }
</html>
<%args>
$username => ''
</%args>
<%init>
if ($username){
$session->user( new Object::Generic( name => $username ));
}
</%init>
DESCRIPTION
Object::Generic::Session implements a perl object that inherits from both Session.pm (a variation on Apache::Session) and Object::Generic.
A Session.pm object allows you to get and set persistent key/value pairs with a syntax like $session->get($key) and $session->set(key => $value).
This package adds Object::Generic's other interfaces to the key/value pairs, namely $session->key (equivalent to get($key)), $session->get_key, $session->key($value) (equivalent to set(key=>$value)), and $session->set_key($value). In addition, keys which aren't defined return an Object::Generic::False which allow method chaining even if the key isn't defined. Thus an expression like $session->user->name won't crash even if $session->user is not defined.
Apache::Session, Apache::Cookie, Session.pm, and Object::Generic are prerequisites for this package. It has not been tested with Apache 2.x.
SEE ALSO
Object::Generic, Class::DBI, Apache::Session, Session, Apache::Cookie
AUTHOR
Jim Mahoney, Marlboro College <mahoney@marlboro.edu<gt>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Jim Mahoney
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.