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

NAME

MVC::Neaf::X::Session::SQL - SQL-based session backend for Not Even A Framework.

DESCRIPTION

Store session data in a SQL table. Consider a pre-existing DB connection and a low-traffic site where having additional session storage (e.g. key-value) would be an overkill.

SYNOPSIS

    my $session_engine = MVC::Neaf::X::Session::SQL->new (
        dbh         => $my_db_conn,
        table       => 'session',
        id_as       => 'session_name',
        content_as  => 'json_data',        # optional but recommended
        expire_as   => 'expires',          # optional, unix timestamp
        mapped_cols => [ 'user_id', ... ], # optional
    );

METHODS

new (%options)

%options may include

  • dbh (required) - database connection to use, see DBI.

  • table (required) - name of table to use for sessions.

  • id_as (required) - name of session id column. Must accept long arbitrary strings.

  • content_as - name of column containing encoded session data. Must accept long arbitrary strings.

  • expire_as - name of column storing expiration date as a Unix timestamp (must accept integer number).

  • mapped_cols - array of session fields that are mapped into database columns. The field name MUST be equal to column name.

At least one of content_as and mapped_cols MUST be present, even though it could be technically possible to use sessions with id and timestamp only.

store( $id, $str, $hash )

Store data in database, using $hash as additional indexed fields if any defined.

fetch( $id )

Fetch data from table.

Returns { data => stringified_data, orevvide => { individual_fields } }

LICENSE AND COPYRIGHT

This module is part of MVC::Neaf suite.

Copyright 2016-2018 Konstantin S. Uvarin khedin@cpan.org.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.