NAME

OpenInteract::Session - Implement session handling in the framework

SYNOPSIS

# In pkg/base/OpenInteract.pm
# Note that $R->session translates to OpenInteract::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

<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. Implementations using DB_File, GDBM, NFS, etc. 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.

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 hash. 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.

TO DO

Nothing

BUGS

None known.

SEE ALSO

Apache::Session

OpenInteract::Template -- assigns the session hash informatioon 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 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>