The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::Plugin::Session::Store::DOD - Store your sessions in a database using Data::ObjectDriver.

SYNOPSIS

    # Create a table in your database for sessions
    CREATE TABLE sessions (
        id           char(72) primary key,
        session_data text,
        expires      int(10)
    );
    
    # Create a Data::ObjectDriver model
    package BaseObject::M::Session;
    use base qw( Data::ObjectDriver::BaseObject );

    use Data::ObjectDriver::Driver::DBI;

    __PACKAGE__->install_properties({
        columns     => [ 'id', 'session_data', 'expires' ],
        primary_key => [ 'id' ],
        datasource  => 'sessions',
        get_driver  => sub {
            Data::ObjectDriver::Driver::DBI->new(
                dsn => "dbi:SQLite:session.db",
            ),
        },
    });

    # In your app
    use Catalyst qw/Session Session::Store::DOD Session::State::Cookie/;
    
    # Connect directly to the database
    MyApp->config->{session} = {
        expires => 3600,
        model   => "BaseObject::M::Session",
    };

    # ... in an action:
    $c->session->{foo} = 'bar'; # will be saved

DESCRIPTION

This storage module will store session data in a database using a Data::ObjectDriver model. It is based on version 0.13 of Catalyst::Plugin::Session::Store::DBI by Andy Grundman <andy@hybridized.org> and is basically a port of his module to use D::OD instead of directly interacting via DBI.

CONFIGURATION

These parameters are placed in the configuration hash under the session key.

expires

The expires column in your table will be set with the expiration value. Note that no automatic cleanup is done on your session data, but you can use the delete_expired_sessions method to perform clean up. You can make use of the Catalyst::Plugin::Scheduler plugin to schedule automated session cleanup.

model

Data::ObjectDriver::BaseObject::Model object which is configuered to interact with your storage engine for session information.

SCHEMA

Your 'sessions' model must contain at minimum the following 3 attributes:

    id           char(72) primary key
    session_data text
    expires      int(10)

The 'id' column should probably be 72 characters. It needs to handle the longest string that can be returned by "generate_session_id" in Catalyst::Plugin::Authentication, plus another 8 characters for internal use. This is less than 72 characters in practice when SHA-1 or MD5 are used, but SHA-256 will need all those characters.

The 'session_data' column should be a long text field. Session data is encoded using Base64 before being stored in the database.

The 'expires' column stores the future expiration time of the session. This may be null for per-user and flash sessions.

METHODS

get_session_data

store_session_data

delete_session_data

delete_expired_sessions

setup_session

These are implementations of the required methods for a store. See Catalyst::Plugin::Session::Store.

SEE ALSO

Catalyst, Catalyst::Plugin::Session, Catalyst::Plugin::Scheduler

AUTHOR

David Recordon, <david@sixapart.com>

Based on Catalyst::Plugin::Session::Store::DBI by Andy Grundman <andy@hybridized.org>

COPYRIGHT

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.