man > CGI::Session::Driver

📖 NAME

CGI::Session::Driver - CGI::Session driver specifications

🚀 Quick Reference

Use CaseCommandDescription
🔧 Write a new driverrequire CGI::Session::Driver; @ISA = qw( CGI::Session::Driver );Declare a driver class that inherits from CGI::Session::Driver
🔗 Initialize session with custom driver$s = CGI::Session->new("driver:your_driver_name", undef, \%options)Create a session object using your driver, with optional driver-specific parameters
💾 Store session datasub store { my ($self, $sid, $datastr) = @_; }Save serialized data for a given session ID
📂 Retrieve session datasub retrieve { my ($self, $sid) = @_; }Fetch previously stored serialized data; return 0/"" if not found
🗑️ Remove session datasub remove { my ($self, $sid) = @_; }Delete storage associated with a session ID
🔍 Traverse all sessionssub traverse { my ($self, $coderef) = @_; }Execute a callback for every stored session ID

📝 SYNOPSIS

require CGI::Session::Driver;
@ISA = qw( CGI::Session::Driver );

📖 DESCRIPTION

CGI::Session::Driver is a base class for all CGI::Session's native drivers. It also documents driver specifications for those willing to write drivers for different databases not currently supported by CGI::Session.

❓ WHAT IS A DRIVER

Driver is a piece of code that helps CGI::Session library to talk to specific database engines, or storage mechanisms. To be more precise, driver is a .pm file that inherits from CGI::Session::Driver and defines retrieve(), store() and remove() methods.

🧩 BLUEPRINT

The best way of learning the specs is to look at a blueprint of a driver:

package CGI::Session::Driver::your_driver_name;
use strict;
use base qw( CGI::Session::Driver CGI::Session::ErrorHandler );

sub init {
    my ($self) = @_;
    # optional
}

sub DESTROY {
    my ($self) = @_;
    # optional
}

sub store {
    my ($self, $sid, $datastr) = @_;
    # Store $datastr, which is an already serialized string of data.
}

sub retrieve {
    my ($self, $sid) = @_;
    # Return $datastr, which was previously stored using above store() method.
    # Return $datastr if $sid was found. Return 0 or "" if $sid doesn't exist
}

sub remove {
    my ($self, $sid) = @_;
    # Remove storage associated with $sid. Return any true value indicating success,
    # or undef on failure.
}

sub traverse {
    my ($self, $coderef) = @_;
    # execute $coderef for each session id passing session id as the first and the only
    # argument
}

1;

All the attributes passed as the second argument to CGI::Session's new() or load() methods will automatically be made driver's object attributes. For example, if session object was initialized as following:

$s = CGI::Session->new("driver:your_driver_name", undef, {Directory=>'/tmp/sessions'});

You can access value of 'Directory' from within your driver like so:

sub store {
    my ($self, $sid, $datastr) = @_;
    my $dir = $self->{Directory};   # <-- in this example will be '/tmp/sessions'
}

Optionally, you can define "init()" method within your driver to do driver specific global initialization. "init()" method will be invoked only once during the lifecycle of your driver, which is the same as the lifecycle of a session object.

For examples of "init()" look into the source code of native CGI::Session drivers.

⚙️ METHODS

This section lists and describes all driver methods. All the driver methods will receive driver object ($self) as the first argument. Methods that pertain to an individual session (such as "retrieve()", "store()" and "remove()") will also receive session id ($sid) as the second argument.

Following list describes every driver method, including its argument list and what step of session's life they will be invoked. Understanding this may help driver authors.

📌 NOTES

🔄 BACKWARDS COMPATIBILITY

Version 4.0 of CGI::Session's driver specification is NOT backward compatible with the previous specification. If you already have a driver developed to work with the previous version you're highly encouraged to upgrade your driver code to make it compatible with the current version. Fortunately, current driver specs are a lot easier to adapt to.

For support information see CGI::Session.

📜 LICENSING

For support and licensing see CGI::Session.


perl v5.22.1   2016-01-15   CGI::Session::Driver(3pm)

CGI::Session::Driver
📖 NAME 🚀 Quick Reference 📝 SYNOPSIS 📖 DESCRIPTION ❓ WHAT IS A DRIVER
🧩 BLUEPRINT
⚙️ METHODS
📌 NOTES
🔄 BACKWARDS COMPATIBILITY 📜 LICENSING

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-08 06:05 @216.73.217.175
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^