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

NAME

OpenInteract::Session - Implement session handling in the framework

SYNOPSIS

 # In OpenInteract.pm Note that $R->session translates to
 # OpenInteract::Session::Blah thanks to the server configuration key
 # 'system_alias::session'

 $R->session->parse;

 # Access the data the session from any handler

 $R->{session}{my_stateful_data} = "oogle boogle";
 $R->{session}{favorite_colors}{red} += 5;

 # And from any template you can use the OI template plugin (see
 # OpenInteract::Template::Plugin)

 <p>The weight of your favorite colors are:
 [% FOREACH color = keys OI.session.favorite_colors %]
   * [% color %] -- [% OI.session.favorite_colors.color %]
 [% END %]

 # in the main content handler, OpenInteract.pm
 # Only call once you're done accessing the data

 $R->session->save;

DESCRIPTION

Sessions are a fundamental part of OpenInteract, and therefore session handling is fairly transparent. We rely on Apache::Session to do the heavy-lifting for us.

This handler has two public methods: parse() and save(). Guess in which order they are meant to be called?

This class also requires you to implement a subclass that overrides the _create_session method with one that returns a valid Apache::Session tied hashref. OpenInteract provides OpenInteract::Session::DBI for DBI databases, OpenInteract::Session::SQLite for SQLite databases, and , OpenInteract::Session::File using the filesystem. Implementations using other media are left as an exercise for the reader.

Subclasses should refer to the package variable $OpenInteract::Session::COOKIE_NAME for the name of the cookie to create, and should throw a '310' error of type 'session' if unable to connect to the session data source to create a session.

You can create sessions that will expire if not used by setting the session_info.expires_in server configuration key. See the description below in CONFIGURATION for more information.

METHODS

parse()

Get the session_id and fetch a session for this user; if one does not exist, just set the {session} property of $R to an anonymous hashref. If data exist when we want to save it, we will create a session form it then. Otherwise we will not bother.

save()

Save the session off for later. If we did not initially create one do so now if there is information in {session}.

CONFIGURATION

The following configuration keys are used:

  • session_info.expiration (optional)

    Used to set the time a session lasts. See CGI for an explanation of the relative date strings accepted.

  • session_info.expires_in (optional)

    Used to set the time (in number of minutes) greater than which a session will expire due to inactivity.

TO DO

Nothing

BUGS

None known.

SEE ALSO

Apache::Session

OpenInteract::Template::Plugin: makes the session hash information available to the template

OpenInteract::Cookies::* -- routines for parsing, creating, setting cookie information so we can match up users with session information

COPYRIGHT

Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Chris Winters <chris@cwinters.com>