NAME
AutoSession - Automatically Session module for Web/CGI & scripts.
DESCRIPTION
This module implements an automatically Session that works for Web/CGI and normal scripts.
USAGE
use AutoSession ;
my $SESSION = AutoSession->new(
name => 'FOO' ,
driver => 'file' ,
directory => '/tmp/sessions' ,
expire => 60*60*24 ,
) ;
## Ensure that the session is clean/new (withoout keys).
## This will delete existent keys:
$SESSION->clean ;
## the session id:
my $id = $SESSION->id ;
## The file path of the session (Drive file):
my $file = $SESSION->local ;
## Create/set the keys
$SESSION->{key1} = k1 ;
$SESSION->{key2} = k2 ;
## Save and close the session.
## Note that when you set a key the session is atomatically saved.
$SESSION->close ;
## Force the save: (You don't need to use it, since this is AutoSession.)
$SESSION->save ;
## Delete session when all the work is done:
$SESSION->delete ;
METHODS
new
Create/load the session.
Arguments:
- id
-
The ID of an existent session to load.
If not paste, a new session is created.
- idsize
-
The size/length of the ID.
Default: 32
- name
-
The name of the session. Can be used to identify the sessions when you use more than one at the same time.
** Accept only [\w].
- driver
-
The DRIVER to use. Options:
FILE MYSQL HDB
** Use HDB for generic database, since HDB works with any DB!
- expire
-
Expire time of the session.
Options:
60s => 60 seconds 30m => 30 minutes 2h => 2 hours 2d => 2 days 1mo => 1 month 1y => 1 year 60 => 60 seconds
Default:
New sessions: 1 hour Loading: the previous value in the session.
** If you paste the expire arument when you are loading an already existent session, you reset the expire of the session.
- base64
-
Encode the data to base64 before save it.
** Good if you can't use binary data when saving.
- directory|dir
-
The directory to save/load the session.
** Only when using the DRIVE file.
clean|clear
Clean the session, removing all the keys.
open
Open the session if it has been closed.
close
Close the session and avoid future access/changes in the session object.
refresh
Refresh the session (only if changed).
load
Load/reload the session.
save
Save the session in the file or database.
id
Return the ID of the session.
name
Return the name of the session.
driver
Return the driver type of the session.
autoload
Return TRUE when the SESSION can be autoloaded.
** This method is only for when used with HPL!
cookie_line
Return the cookie line to send to the browser.
hash_ref
Return the HASH reference inside the object. The real place where the keys are stored in the memory, since this is a tied object.
local
Return the local where the session is saved. Have a different format for the drivers:
DRIVE: FORMAT:
----------------------------------------
FILE => /tmp/SESSION-IDFOO.tmp ## the file path
MYSQL => user@mydomain:3648/tablex ## the DB and host
HDB => dbtype&user@mydomain/tablex ## the HDB and host
HDB => dbtype&filepath#tablex ## the HDB and file path (for flat DB)
EXPIRE
The expire sistem is very simple, you just set the argument expire when you create/load the session.
if the session stay more than N seconds (the expire time) without access, it's expired (deleted).
KEYS
The keys of the session object paste through a tied HASH, that save them each time that they are changed. And when you access them it check for updates in the session, in case to be changed by other process.
** Note that since this is a tied hash, if you use HASH references inside a key, changes of sub-keys can't be detected. For example:
## Create the key 'foo' with a HASH ref.
$session->{foo}{bar} = 1 ;
## Reset bar, but this won't auto-save the session.
$session->{foo}{bar} = 2 ;
## So, you need to force the auto-save:
$session->save ;
## But normal keys auto-save the session:
$session->{k} = 10 ;
SEE ALSO
HPL, Apache::Session, CGI::Session.
AutoSession is the default module of the HPL sessions.
AUTHOR
Graciliano M. P. <gm@virtuasites.com.br>
I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P
Created for HPL. But as a external module to use it anywhere.
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.