PET::Session

This is a base session implementation.  It works by default, but there are many implementing classes.  This one uses Storable to freeze/thaw data, and stores session data to disk at $BASEPATH/sessions

Implementing classes usually only override store and load.  Check out the implementations for an example!  There are standard session classes shipped with PET.

Summary
PET::SessionThis is a base session implementation.
Variables
$DISP
$CLEANUP_THRESHOLD
$SESSION_FILE_EXPIRES
Functions
newCreate instance.
init (%params)Init is called from new.
startThis method is called at each page.
access ($stored)Signal access to session.
createNameCreate the name of the session cookie and returns it.
thawThaw the session object from “binary data”.
freezeFreeze hashref to binary data.
storeSerialize and save session data.
imvalidate ()Invalidate cookie by deleting it from disk.
invalidate
finish
load
get
set
sessionChangedSet or get value of “SESSION_CHANGED”, which shows if the session should be synced.
getSesidReturn SESID.
onStartGet or set SUB that is called on session creation.
cleanupOldCalled conditionally from “start” when a (new) cookie is created.

Variables

$DISP

our $DISP

$CLEANUP_THRESHOLD

our $CLEANUP_THRESHOLD

$SESSION_FILE_EXPIRES

our $SESSION_FILE_EXPIRES

Functions

new

sub new

Create instance.  Must be subclassable.

init (%params)

sub init

Init is called from new.  Some implementations might need some basic init-phase stuff.

start

sub start

This method is called at each page.  It creates a cookie if there is none, if there is one, it fetches and returns it.

access ($stored)

sub access

Signal access to session.  This (by default empty) method can be used to store when the session was last touched.  It is called from “finish()”.  $stored [0|1] is passed, which tells if at this run the session has been modified and saved or not.

createName

sub createName

Create the name of the session cookie and returns it.

thaw

sub thaw

Thaw the session object from “binary data”.  By default this is the thaw method of the Storable package -- but it can be overriden.  It is recommended but not mandatory for implementing classes to use this method.

Gets binary data, returns hashref.

freeze

sub freeze

Freeze hashref to binary data.  See also thaw.

store

sub store

Serialize and save session data.  Gets SESID and SESSION from $self, and stores them.

imvalidate ()

Invalidate cookie by deleting it from disk.  (Should we delete the cookie, too?)

invalidate

sub invalidate

finish

sub finish

load

sub load

get

sub get

set

sub set

sessionChanged

sub sessionChanged

Set or get value of “SESSION_CHANGED”, which shows if the session should be synced.

getSesid

sub getSesid

Return SESID.

onStart

sub onStart

Get or set SUB that is called on session creation.

If you call onStart with a subref, it will be stored, and later at any time when a session is initialized, that subref is called upon.  This way you can attach actions to session creation -- this actually is a method to set up a callback.

Usually you want to call onStart from you API at INIT time!

cleanupOld

sub cleanupOld

Called conditionally from “start” when a (new) cookie is created.  Should erase old sessions from disk.

If you override this method, try to make it FAST.

This is a very lightweight session handler optimized for speed.
our $DISP
our $CLEANUP_THRESHOLD
our $SESSION_FILE_EXPIRES
sub new
Create instance.
sub init
Init is called from new.
sub start
This method is called at each page.
sub access
Signal access to session.
sub createName
Create the name of the session cookie and returns it.
sub thaw
Thaw the session object from “binary data”.
sub freeze
Freeze hashref to binary data.
sub store
Serialize and save session data.
sub invalidate
sub finish
sub load
sub get
sub set
sub sessionChanged
Set or get value of “SESSION_CHANGED”, which shows if the session should be synced.
sub getSesid
Return SESID.
sub onStart
Get or set SUB that is called on session creation.
sub cleanupOld
Called conditionally from “start” when a (new) cookie is created.
Close