Data::Session::CGISession - A persistent session manager


Back to Top


NAME

the Data::Session manpage - A persistent session manager

Back to Top


The Design of Data::Session, contrasted with CGI::Session

For background, read the docs (including the Changes files) and bug reports for both the Apache::Session manpage and the CGI::Session manpage.

The interface to the Data::Session manpage is not quite compatible with that of the CGI::Session manpage, hence the new namespace.

The purpose of the Data::Session manpage is to be a brand-new alternative to both the Apache::Session manpage and the CGI::Session manpage.

Back to Top


Aliases for Method Names

Aliases for method names are not supported.

In the CGI::Session manpage, methods etime() and expires() were aliased to expire(). This is not supported in the Data::Session manpage.

the Data::Session manpage does have an etime() method, Method: etime() in the Data::Session manpage, which is different.

In the CGI::Session manpage, method header() was aliased to http_header(). Only the latter method is supported in the Data::Session manpage. See Method: cookie() and Method: http_header([@arg]).

In the CGI::Session manpage, id generators had a method generate_id() aliased to generate(). This is not supported in the Data::Session manpage.

In the CGI::Session manpage, method param_dataref() was aliased to dataref(). Neither of these methods is supported in the Data::Session manpage. If you want to access the session data, use my($hashref) = $session -> session.

Back to Top


Backwards-compatibility

This topic is sometimes used as a form of coercion, which is unacceptable, and sometimes leads to a crippled design.

So, by design, the Data::Session manpage is not exactly backwards-compatible with the CGI::Session manpage, but does retain it's major features:

o Specify the basic operating parameters with new(type => $string)

This determines the type of session object you wish to create.

The default value is 'driver:File;id:MD5;serialize:DataDumper'.

And specifically, the format of that case-sensitive string is as expected. See Specifying Session Options in the Data::Session manpage for details.

o Retrieve the session id with the id() method
o Set and get parameters with the param() method
o Ensure session data is saved to disk with the flush() method

Call this just before your program exits.

In particular, as with the CGI::Session manpage, persistent environments stop your program exiting in the way you are used to. This matter is discussed in Trouble with Exiting in the Data::Session manpage.

Back to Top


CGI::Session::ExpireSessions is obsolete

Instead, consider using scripts/expire.pl, which ships with the Data::Session manpage.

Back to Top


Code refs as database handles

Being able to supply a code ref as the value of the 'dbh' parameter to new() is supported.

This mechanism is used to delay creation of a database handle until it is actually needed, which means if it is not needed it is not created.

Back to Top


Class 'v' Object

Calling methods on the class is not supported. You must always create an object.

The reason for this is to ensure every method call, without exception, has access to the per-object data supplied by you, or by default, in the call to new().

Back to Top


The type of the Data::Session object

Controlling the capabilities of the the Data::Session manpage object is determined by the 'type' parameter passed in to new, as Data::Session -> new(type => $string).

A sample string looks like 'driver:BerkeleyDB;id:SHA1;serialize:DataDumper'.

Abbreviation of component key names ('driver', 'id', 'serializer') is not supported.

Such abbreviations were previously handled by the Text::Abbrev manpage. Now, these must be named in full.

The decision to force corresponding class names to lower case is not supported.

Nevertheless, lower-cased input will be accepted. Such input is converted to the case you expect.

This affects the names of various sub-classes. See ID Generators, Serialization Drivers and Storage Drivers.

For example, driver:pg is now driver:Pg, which actually means the Data::Session::Driver::Pg manpage, based on the class name the DBD::Pg manpage.

Back to Top


Exceptions

Exceptions are caught with the Try::Tiny manpage. Errors cause the Data::Session manpage to die.

The only exception to this is the call to new(), which can return undef. In that case, check $Data::Session::errstr.

Back to Top


Global Variables

Global variables are not supported. This includes:

o $CGI::Session::Driver::DBI::TABLE_NAME
o $CGI::Session::Driver::DBI::*::TABLE_NAME
o $CGI::Session::Driver::file::FileName
o $CGI::Session::IP_MATCH
o $CGI::Session::NAME

Back to Top


ID Generators

Id generator classes have been renamed:

o CGI::Session::ID::incr becomes the Data::Session::ID::AutoIncrement manpage
o CGI::Session::ID::md5 becomes the Data::Session::ID::MD5 manpage
o CGI::Session::ID::sha becomes the Data::Session::ID::SHA1 manpage
o CGI::Session::ID::sha256 becomes the Data::Session::ID::SHA256 manpage
o CGI::Session::ID::sha512 becomes the Data::Session::ID::SHA512 manpage
o CGI::Session::ID::static becomes the Data::Session::ID::Static manpage
o CGI::Session::ID::uuid becomes the Data::Session::ID::UUID16 manpage or UUID34 or UUID36 or UUD64

Back to Top


JSON

the Data::Session::Serialize::JSON manpage uses the JSON manpage, not the JSON::Syck manpage.

Managing Object Attributes

The light-weight the Hash::FieldHash manpage is used to manage object attributes.

So, neither Mouse nor Moose, nor any other such class helper, is used.

Back to Top


Method: cookie()

Forcing the query object to have a cookie method is not supported. You may now use a query class which does not provide a cookie method.

The logic of checking the cookie (if any) first (i.e. before checking for a form field of the same name) is supported.

See Method: http_header([@arg]).

Back to Top


Method: http_header([@arg])

The [] indicate an optional parameter.

Returns a HTTP header. This means it does not print the header. You have to do that, when appropriate.

Forcing the document type to be 'text/html' when calling http_header() is not supported. You must pass in a document type to http_header(), as $session -> http_header('-type' => 'text/html'), or use the query object's default. Both CGI and the CGI::Simple manpage default to 'text/html'.

the Data::Session manpage handles the case where the query object does not have a cookie() method.

The @arg parameter, if any, is passed to the query object's header() method, after the cookie parameter, if any.

Back to Top


Method: load()

The new load() takes no parameters.

Back to Top


Method: new()

Excess versions of new() are not supported.

The new new() takes a hash of parameters.

This hash will include all options previously passed in in different parameters to new(), including $dsn, $query, $sid, \%dsn_args and \%session_params.

Back to Top


Name Changes

Class name changes are discussed in ID Generators, Serialization Drivers and Storage Drivers.

As discussed in Method: new() in the Data::Session manpage, these name changes are both the result of cleaning up all the options to new(), and because the option names are now also method names.

o DataColName becomes data_col_name

This is used in the call to new().

o DataSource becomes data_source

This is used in the call to new().

o generate_id becomes generate

This is used in various id generator classes, some of which provided generate as an alias.

o Handle becomes dbh

This is used in the call to new().

o IdColName becomes id_col_name

This is used in the call to new().

o IDFile becomes id_file

This is used in the call to new(), and in the '... id:AutoIncrement ...' id generator.

o IDIncr becomes id_step

This is used in the call to new(), and in the '... id:AutoIncrement ...' id generator.

o IDInit becomes id_base

This is used in the call to new(), and in the '... id:AutoIncrement ...' id generator.

Back to Top


param()

Excess versions of param() will not be supported.

Use param($key => $value) to set and param($key) to get.

param() may be passed a hash, to set several key/value pairs in 1 call.

Back to Top


POD

All POD has been re-written.

Back to Top


Race Conditions

The race handling code in the CGI::Session::Driver::postgresql manpage has been incorporated into other the Data::Session::Driver::* manpage drivers.

Back to Top


Serialization Drivers

Serializing classes have been renamed:

o CGI::Session::Serialize::default becomes the Data::Session::Serialize::DataDumper manpage
o CGI::Session::Serialize::freezethaw becomes the Data::Session::Serialize::FreezeThaw manpage
o CGI::Session::Serialize::json becomes the Data::Session::Serialize::JSON manpage

The latter will use the JSON manpage. In the past the YAML::Syck manpage was used.

o CGI::Session::Serialize::storable becomes the Data::Session::Serialize::Storable manpage
o CGI::Session::Serialize::yaml becomes the Data::Session::Serialize::YAML manpage

The latter uses the YAML::Tiny manpage. In the past either the YAML::Syck manpage or the YAML manpage was used.

Back to Top


Session ids will be mandatory

The ability to create a Perl object without a session id is not supported.

Every time a object of type the Data::Session manpage is created, it must have an id.

This id is either supplied by the caller, taken from the query object, or one is generated.

See Specifying an Id in the Data::Session manpage for details.

Back to Top


Session modification

the CGI::Session manpage tracks calls to param() to set a flag if the object is modified, so as to avoid writing the session to disk if nothing has been modified.

This includes checking if setting a param's value to the value it already has.

The behaviour is supported.

Back to Top


Session Parameters

the CGI::Session manpage had these internal object attributes (parameters) not available to the user:

o _DATA

Hashref: Keys: _SESSION_ATIME, _SESSION_CTIME, _SESSION_ID and _SESSION_REMOTE_ADDR.

o _DSN

Hashref.

o _OBJECTS

Hashref.

o _DRIVER_ARGS

Hashref.

o _CLAIMED_ID

Scalar.

o _STATUS

Scalar (bitmap).

o _QUERY

Scalar.

the Data::Session manpage has these internal object attributes (parameters):

o _SESSION_ATIME

Scalar: Last access time.

o _SESSION_CTIME

Scalar: Creation time.

o _SESSION_ETIME

Scalar: Expiry time.

o _SESSION_ID

Scalar: The id.

o _SESSION_PTIME

Hashref: Expiry times of parameters.

the Data::Session manpage stores user data internally in a hashref, and the module reserves keys starting with '_'.

Of course, it has a whole set of methods to manage state.

Back to Top


Session States

the CGI::Session manpage objects can be one of 6 states. Every attempt has been made to simplify this design.

Back to Top


Storage Drivers

Classes related to DBI/DBD will use DBD::* style names, to help beginners.

Hence (with special cases):

o CGI::Session::Driver::db_file becomes the Data::Session::Driver::BerkeleyDB manpage

The latter no longer uses DB_File.

o CGI::Session::Driver::file becomes the Data::Session::Driver::File manpage
o CGI::Session::Driver::memcached becomes the Data::Session::Driver::Memcached manpage
o CGI::Session::Driver::mysql becomes the Data::Session::Driver::mysql manpage
o CGI::Session::Driver::odbc becomes the Data::Session::Driver::ODBC manpage
o CGI::Session::Driver::odbc becomes the Data::Session::Driver::Oracle manpage
o CGI::Session::Driver::postgresql becomes the Data::Session::Driver::Pg manpage
o CGI::Session::Driver::sqlite becomes the Data::Session::Driver::SQLite manpage

Back to Top


Tests

All tests have been re-written.

Back to Top


The Version of Perl

Perl 5 code will be used.

Back to Top


YAML

the Data::Session::Serialize::YAML manpage uses the YAML::Tiny manpage, not the YAML::Syck manpage or the YAML manpage.

Back to Top


Author

the Data::Session manpage was written by Ron Savage <ron@savage.net.au> in 2010.

Home page: http://savage.net.au/index.html.

Back to Top


Copyright

Australian copyright (c) 2010, Ron Savage.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License, a copy of which is available at:
        http://www.opensource.org/licenses/index.html

Back to Top

 Data::Session::CGISession - A persistent session manager