| OpenFrame-WebApp documentation | Contained in the OpenFrame-WebApp distribution. |
OpenFrame::WebApp::Segment::Session::Loader - abstract pipeline segment to load sessions
# abstract class - cannot be used directly
use Pipeline;
use OpenFrame::WebApp;
my $pipe = new Pipeline;
my $sfactory = new OpenFrame::WebApp::Session::Factory()->type('mem_cache');
$pipe->store->set( $sfactory );
# abstract - must use a sub-class:
my $sloader = new OpenFrame::WebApp::Segment::Session::CookieLoader;
$pipe->add_segment( $sloader );
...
$pipe->dispatch;
The OpenFrame::WebApp::Segment::Session::Loader class is an abstract session
loading segment. It inherits its interface from Pipeline::Segment.
On dispatch() a session is fetched or created using the Pipeline's stored
OpenFrame::WebApp::Session::Factory, and a new
OpenFrame::WebApp::Segment::Session::Saver object is added to the cleanup
pipeline so that any modifications to the session will be saved for the next
request.
dispatch this segment.
looks for session id with find_session_id(), and creates/fetches the
session using OpenFrame::WebApp::Session::Factory.
returns a new OpenFrame::WebApp::Segment::Session::Saver object for this
$session.
abstract method for finding the session id.
Steve Purkis <spurkis@epn.nu>
Based on OpenFrame::AppKit::Segment::SessionLoader, by James A. Duncan
Copyright (c) 2003 Steve Purkis. All rights reserved. Released under the same license as Perl itself.
| OpenFrame-WebApp documentation | Contained in the OpenFrame-WebApp distribution. |
package OpenFrame::WebApp::Segment::Session::Loader; use strict; use warnings::register; use Error; use OpenFrame::WebApp::Error::Abstract; use OpenFrame::WebApp::Session; use OpenFrame::WebApp::Session::Factory; use OpenFrame::WebApp::Segment::Session::Saver; our $VERSION = (split(/ /, '$Revision: 1.6 $'))[1]; use base qw( Pipeline::Segment ); sub dispatch { my $self = shift; my $pipe = shift; my $session = $self->get_session(); my $saver_seg = $self->create_saver_segment( $session ); return( $session, $saver_seg ); } sub get_session { my $self = shift; my $sfactory = $self->store->get('OpenFrame::WebApp::Session::Factory'); my $session; if (my $id = $self->find_session_id) { $session = $sfactory->fetch_session( $id ); } unless ($session) { $session = $sfactory->new_session(); } return $session; } sub create_saver_segment { my $self = shift; my $session = shift; new OpenFrame::WebApp::Segment::Session::Saver()->session( $session ); } sub find_session_id { my $self = shift; throw OpenFrame::WebApp::Error::Abstract( class => ref($self) ); } 1; __END__