NAME
DeltaX::Session - Perl module for session management
_____
/ \ _____ ______ ______ ___________
/ \ / \\__ \ / ___// ___// __ \_ __ \
/ Y \/ __ \_\___ \ \___ \\ ___/| | \/
\____|__ (____ /____ >____ >\___ >__|
\/ \/ \/ \/ \/ project
SYNOPSIS
use DeltaX::Database;
use DeltaX::Session;
my $db = new DeltaX::Database(...);
my $sess = new DeltaX::Session(db=>$db, table_name=>'my_sessions');
my $sid = '12345'; # Session ID
$sess->put($sid, key1=>'data1', key2=>'data2');
if (!$sess->exist($sid)) {
# some error
}
my %data = $sess->get($sid);
DESCRIPTION
This module is prepared for session management (especially for masser applications). It can store session information in database table (preffered), shared memory or file (both in practise untested). Session is identified by SID - Session IDentification - some unique identifier composed from a-z, A-Z and 0-9 characters (for example md5_hex from Digest::MD5 is good for creating it). If you use database table, you must create table with this structure:
create table <name_as_you_want> (
sid varchar(32) not null, -- according to SID you will use
sdata varchar(2000), -- as data you will store
ts timestamp -- date & time
primary key (sid)
);
If you use shared memory, you must have IPC::SharedCache installed. WARNING: Not fully implemented.
If you use file, you must have module for selected storage type installed (default is GDBM_File).
There are no functions which allow you to modify or delete SID (because of performance issues).
FUNCTIONS
new()
Constructor. It uses parameters in key => value form:
- db
-
Reference to initialized DeltaX::Database. If set, session data will be stored in this database.
- table_name
-
If you are using database storage, this is a table name which will hold data (default is 'sessions').
- shm_key
-
Shared memory key (up to 4 characters - see IPC::SharedCache). If set, session data will be stored in shared memory with this key.
- shm_segment
-
Shared memory segment size (only valid if shm_key set) - see IPC::SharedCache for explanation. Default is 10000 bytes.
- shm_max
-
Maximum shared memory size (only valid if shm_key set) - see IPC::SharedCache for explanation. Default is 1000000 bytes.
- shm_timeout
-
Timeout in seconds, after which will be record in cache invalidated (see IPC::SharedCache, validate_callback). Default is 300 seconds.
- file
-
Filename of file in which session data will be stored.
- db_file
-
Database file type to store session data, default is GDBM_File. Appropriate module must be installed.
put()
This function allows you to put some data linked to given SID. The first parameter is SID, other parameters are in key => value form. Returned values:
- -1 - no SID given
- -2 - SID already exists
- -3 - parameters are not in key => value form
- -5 - database error while inserting new data
- 1 - ok
exist()
Tests if given SID exists in storage, only one required parameter is SID. Returns true if SID exists, otherwise returns false (0).
get()
Returns hash with values assigned to given SID (first and required parameter). Returns undef in case of error.
free()
Frees resources used by module (especially closes opened statements if using database).