OpenInteract::Session - Implement session handling in the framework
# 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;
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?
parse()
save()
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.
$OpenInteract::Session::COOKIE_NAME
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.
session_info.expires_in
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.
$R
Save the session off for later. If we did not initially create one do so now if there is information in {session}.
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.
Nothing
None known.
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
OpenInteract::Cookies::*
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.
Chris Winters <chris@cwinters.com>
To install OpenInteract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenInteract
CPAN shell
perl -MCPAN -e shell install OpenInteract
For more information on module installation, please visit the detailed CPAN module installation guide.