Data::...Session(3pm)
π NAME π
Data::Session β A persistent session manager. That's the name, that's the whole job description, iconic behavior only. π
Oh and btw, in case you were wondering where you wandered into: this is the Data::...Session(3pm) page, from the User Contributed Perl Documentation. It's a long one so it comes in parts, and this is part 1. π«Ά
β¨ The Design of Data::Session, contrasted with CGI::Session β¨
Okay so, for background, bestie, go read the docs (Changes files included) and the bug reports for both Apache::Session and CGI::Session. That's the lore. π
The interface to Data::Session is not quite compatible with that of CGI::Session, hence the new namespace. Different girl, different name tag.
The purpose of Data::Session is to be a brand-new alternative to both Apache::Session and CGI::Session. Glow-up era. β¨
π« Aliases for Method Names π«
Aliases for method names are not supported. Periodt.
- In
CGI::Session, the methodsetime()andexpires()were aliased toexpire(). This is not supported inData::Session. Data::Sessiondoes have anetime()method β see "Method: etime()" in Data::Session β and it is different. Do not get it twisted. π- In
CGI::Session, the methodheader()was aliased tohttp_header(). Only the latter method is supported inData::Session. Peep "Method: cookie()" and "Method: http_header([@arg])". - In
CGI::Session, id generators had a methodgenerate_id()aliased togenerate(). This is not supported inData::Session. - In
CGI::Session, the methodparam_dataref()was aliased todataref(). Neither of these methods is supported inData::Session. If you want to access the session data, usemy($hashref) = $session -> session.
π Backwards-compatibility π
Real talk: this topic is sometimes used as a form of coercion, which is unacceptable, and sometimes it leads to a crippled design. We don't play that. π
So, by design, Data::Session is not exactly backwards-compatible with CGI::Session, but it does retain its major features:
- Specify the basic operating parameters with
new(type => $string)This determines the type of session object you wish to create. Default:'driver:File;id:MD5;serialize:DataDumper'. And specifically, the format of that case-sensitive string is as expected. See "Specifying Session Options" in Data::Session for details. - Retrieve the session id with the
id()method - Set and get parameters with the
param()method - Ensure session data is saved to disk with the
flush()method Call this just before your program exits. In particular, as withCGI::Session, persistent environments stop your program exiting in the way you are used to. This matter is discussed in "Trouble with Exiting" in Data::Session.
π CGI::Session::ExpireSessions is obsolete π
Instead, consider using scripts/expire.pl, which ships with Data::Session. She's retired, the new script is literally right there in the box. π
π§ 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. Efficiency queen, no wasted work. π
π Class 'v' Object π
Calling methods on the class is not supported. You must always create an object.
The reason for this? 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(). It's giving accountability. π
π The type of the Data::Session object π
Controlling the capabilities of the Data::Session 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', 'serialize') is not supported.
Such abbreviations were previously handled by Text::Abbrev. Now, these must be named in full. No shortcuts, bestie. π€
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 Data::Session::Driver::Pg, based on the class name DBD::Pg. Lowercase era is over, we're capitalizing now. β¨
π Exceptions π
Exceptions are caught with Try::Tiny. Errors cause Data::Session to die.
The only exception to this is the call to new(), which can return undef. In that case, check $Data::Session::errstr. That's your one (1) escape hatch. π«Ά
π Global Variables π
Global variables are not supported. This includes:
$CGI::Session::Driver::DBI::TABLE_NAME$CGI::Session::Driver::DBI::*::TABLE_NAME$CGI::Session::Driver::file::FileName$CGI::Session::IP_MATCH$CGI::Session::NAME
π ID Generators π
Id generator classes have been renamed:
CGI::Session::ID::incrbecomesData::Session::ID::AutoIncrementCGI::Session::ID::md5becomesData::Session::ID::MD5CGI::Session::ID::shabecomesData::Session::ID::SHA1CGI::Session::ID::sha256becomesData::Session::ID::SHA256CGI::Session::ID::sha512becomesData::Session::ID::SHA512CGI::Session::ID::staticbecomesData::Session::ID::StaticCGI::Session::ID::uuidbecomesData::Session::ID::UUID16orUUID34orUUID36orUUD64
π¦ JSON π¦
Data::Session::Serialize::JSON uses JSON, not JSON::Syck.
β¨ Managing Object Attributes β¨
The light-weight Hash::FieldHash is used to manage object attributes.
So, neither Mouse nor Moose, nor any other such class helper, is used. Lean, mean, no extra weight. πͺ
π 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. Freedom, honestly. ποΈ
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])".
π Method: http_header([@arg]) π
The [] indicate an optional parameter.
Returns a HTTP header. Which means it does not print the header. You have to do that, when appropriate. She hands you the goods, you handle the shipping. π¦
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 CGI::Simple default to 'text/html'.
Data::Session 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.
πΈ Method: load() πΈ
The new load() takes no parameters. That's it, that's the whole thing. Minimalist queen. β¨
β 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. Everything in one bag now, we love consolidation. π
π₯ Name Changes π₯
Class name changes are discussed in "ID Generators", "Serialization Drivers" and "Storage Drivers".
As discussed in "Method: new()" in Data::Session, 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. Double duty, slay. π
DataColNamebecomesdata_col_nameThis is used in the call tonew().DataSourcebecomesdata_sourceThis is used in the call tonew().generate_idbecomesgenerateThis is used in various id generator classes, some of which providedgenerateas an alias.HandlebecomesdbhThis is used in the call tonew().IdColNamebecomesid_col_nameThis is used in the call tonew().IDFilebecomesid_fileThis is used in the call tonew(), and in the'... id:AutoIncrement ...'id generator.IDIncrbecomesid_stepThis is used in the call tonew(), and in the'... id:AutoIncrement ...'id generator.IDInitbecomesid_baseThis is used in the call tonew(), and in the'... id:AutoIncrement ...'id generator.
π 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. One call, many vibes. β¨
π POD π
All POD has been re-written.
π Race Conditions π
The race handling code in CGI::Session::Driver::postgresql has been incorporated into other Data::Session::Driver::* drivers. Teamwork makes the dream work. π«Ά
π Serialization Drivers π
Serializing classes have been renamed:
CGI::Session::Serialize::defaultbecomesData::Session::Serialize::DataDumperCGI::Session::Serialize::freezethawbecomesData::Session::Serialize::FreezeThawCGI::Session::Serialize::jsonbecomesData::Session::Serialize::JSONThe latter will useJSON. In the pastJSON::Syckwas used.CGI::Session::Serialize::storablebecomesData::Session::Serialize::StorableCGI::Session::Serialize::yamlbecomesData::Session::Serialize::YAMLThe latter usesYAML::Tiny. In the past eitherYAML::SyckorYAMLwas used.
π 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 Data::Session 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 Data::Session for details.
π¦ Session modification π¦
CGI::Session 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. Same energy, kept intact. π
π Session Parameters π
CGI::Session had these internal object attributes (parameters) not available to the user:
_DATAHashref: Keys:_SESSION_ATIME,_SESSION_CTIME,_SESSION_IDand_SESSION_REMOTE_ADDR._DSNHashref._OBJECTSHashref._DRIVER_ARGSHashref._CLAIMED_IDScalar._STATUSScalar (bitmap)._QUERYScalar.
Data::Session has these internal object attributes (parameters):
_SESSION_ATIMEScalar: Last access time._SESSION_CTIMEScalar: Creation time._SESSION_ETIMEScalar: Expiry time._SESSION_IDScalar: The id._SESSION_PTIMEHashref: Expiry times of parameters.
Data::Session stores user data internally in a hashref, and the module reserves keys starting with '_'. So hands off those, bestie.
Of course, it has a whole set of methods to manage state. Obviously. π
π Session States π
CGI::Session objects can be one of 6 states. Every attempt has been made to simplify this design.
β¨ Storage Drivers β¨
okay so bestie, here's the tea on storage drivers π
Classes related to DBI/DBD will use DBD::* style names, to help beginners. iconic.
Hence (with special cases):
CGI::Session::Driver::db_filebecomesData::Session::Driver::BerkeleyDBβ and the latter no longer usesDB_File. periodt.CGI::Session::Driver::filebecomesData::Session::Driver::FileCGI::Session::Driver::memcachedbecomesData::Session::Driver::MemcachedCGI::Session::Driver::mysqlbecomesData::Session::Driver::mysqlCGI::Session::Driver::odbcbecomesData::Session::Driver::ODBCCGI::Session::Driver::oraclebecomesData::Session::Driver::OracleCGI::Session::Driver::postgresqlbecomesData::Session::Driver::PgCGI::Session::Driver::sqlitebecomesData::Session::Driver::SQLite
π§ͺ Tests π§ͺ
All tests have been re-written. no cap, every single one got a glow-up β¨
πͺ The Version of Perl πͺ
Perl 5 code will be used. she's committed to the classic π
πΈ YAML πΈ
Data::Session::Serialize::YAML uses YAML::Tiny, not YAML::Syck or YAML. obsessed with the tiny one fr fr.
π Author π
Data::Session was written by Ron Savage <ron@savage.net.au> in 2010.
Home page: <http://savage.net.au/index.html>.
π 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
and that's the whole vibe check bestie π«Ά this was Data::...Session(3pm) from perl v5.36.0, dated 2023-02-14. slay, go read the docs, periodt πβ¨
π¦ where this page comes from
- debian trixie: libdata-session-perl 1.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-session-perl 1.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-session-perl 1.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-session-perl 1.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms