View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jakub Špičák > deltax-modules-3.14 > DeltaX::Session



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 1.0   Source   Latest Release: deltax-modules-3.17


DeltaX::Session - Perl module for session management

    /     \ _____    ______ ______ ___________
   /  \ /  \\__  \  /  ___//  ___// __ \_  __ \
  /    Y    \/ __ \_\___ \ \___ \\  ___/|  | \/
  \____|__  (____  /____  >____  >\___  >__|
          \/     \/     \/     \/     \/        project


 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);


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).



Constructor. It uses parameters in key => value form:


Reference to initialized DeltaX::Database. If set, session data will be stored in this database.


If you are using database storage, this is a table name which will hold data (default is 'sessions').


Shared memory key (up to 4 characters - see IPC::SharedCache). If set, session data will be stored in shared memory with this key.


Shared memory segment size (only valid if shm_key set) - see IPC::SharedCache for explanation. Default is 10000 bytes.


Maximum shared memory size (only valid if shm_key set) - see IPC::SharedCache for explanation. Default is 1000000 bytes.


Timeout in seconds, after which will be record in cache invalidated (see IPC::SharedCache, validate_callback). Default is 300 seconds.


Filename of file in which session data will be stored.


Database file type to store session data, default is GDBM_File. Appropriate module must be installed.


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


Tests if given SID exists in storage, only one required parameter is SID. Returns true if SID exists, otherwise returns false (0).


Returns hash with values assigned to given SID (first and required parameter). Returns undef in case of error.


Frees resources used by module (especially closes opened statements if using database).

syntax highlighting: