The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Object::Generic::Session - an apache session with an interface like Class::DBI.


 # 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
 %             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.)
 % if ($session->user){
    Hi <% $session->user->name %>.  Welcome back.
 % } else { 
      Please log in: <input type="text" name="username" />
 % }
   $username => ''
   if ($username){
      $session->user( new Object::Generic( name => $username ));


Object::Generic::Session implements a perl object that inherits from both (a variation on Apache::Session) and Object::Generic.

A 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,, and Object::Generic are prerequisites for this package. It has not been tested with Apache 2.x.


Object::Generic, Class::DBI, Apache::Session, Session, Apache::Cookie


Jim Mahoney, Marlboro College <<gt>


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.