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

NAME

OpenFrame::WebApp::Session - sessions for OpenFrame-WebApp

SYNOPSIS

  use OpenFrame::WebApp::Session;

  my $session = new OpenFrame::WebApp::Session()
     ->set($key1, $val1)->set($key2, $val2);

  $val = $session->get( $key );

  my $id = $session->store();

  my $restored = OpenFrame::WebApp::Session->fetch( $id );

DESCRIPTION

The OpenFrame::WebApp::Session class is an abstract wrapper around session storing classes like Cache::FileCache, CGI::Session, Apache::Session, etc.

In WebApp, sessions are a storable hash with a session id, and an expiry period.

Just incase something like Pixie is used to store the sessions, you should always use the set/get methods to retrieve keys from the hash.

This class was meant to be used with OpenFrame::WebApp::Session::Factory.

METHODS

types

set/get the hash of $session_types => $class_names known to this class.

$session->id

set/get the session id (stored as 'session_id', FYI).

$session->expiry

set/get the expiry period (stored as 'expiry_period', FYI). This should be a string compatible with Time::ParseDate.

$time = $session->get_expiry_seconds

parses the expiry period with Time::ParseDate, and returns the result in seconds.

Note: $time == undef implies no expiry time, whereas $time <= 0 implies expires immediately.

$session->set( $key, $val )

associates $key with $val, and returns this object.

$val = $session->get( $key )

returns value associated with $key.

$id = $session->store

abstract method, saves the session to disk and returns the session id.

$session = $class->fetch( $id )

abstract method, returns the session with the given $id or undef if not found or expired.

$session->remove( [ $id ] )

abstract method, removes this object from the store, and returns this object. if called as a class method, $id is expected.

$id = $session->generate_id

internal method to generate a new session id.

SUB-CLASSING

Read through the source of this package and the known sub-classes first. The minumum you need to do is this:

  use base qw( OpenFrame::WebApp::Session );

  OpenFrame::WebApp::Session->types->{my_type} = __PACKAGE__;

  sub store {
      ...
      return $id;
  }

  sub fetch {
      ...
      return new Some::Session();
  }

  sub remove {
      ...
      return $self;
  }

You must register your session type if you want to use the Session::Factory.

AUTHOR

Steve Purkis <spurkis@epn.nu>

Based on OpenFrame::AppKit::Session by James A. Duncan

COPYRIGHT

Copyright (c) 2003 Steve Purkis. All rights reserved. Released under the same license as Perl itself.

SEE ALSO

Time::ParseDate, OpenFrame::WebApp::Sesssion::Factory, OpenFrame::WebApp::Sesssion::FileCache, OpenFrame::WebApp::Segment::Sesssion::Loader

Similar modules:

OpenFrame::AppKit::Session, CGI::Session, Apache::Session