Apache...rapper(3pm)
NAME π
Apache::Session::Wrapper β a simple wrapper around Apache::Session.
Also: this is the Apache...rapper(3pm) page from User Contributed Perl Documentation, bestie. Part 1 of 2, so buckle up. π«Ά
β¨ SYNOPSIS β¨
my $wrapper =
Apache::Session::Wrapper->new( class => 'MySQL',
handle => $dbh,
cookie_name => 'example-dot-com-cookie',
);
# will get an existing session from a cookie, or create a new session
# and cookie if needed
$wrapper->session->{foo} = 1;
π¦ DESCRIPTION π¦
This module is a simple wrapper around Apache::Session which provides some methods to simplify getting and setting the session id.
It can use cookies to store the session id, or it can look in a provided object for a specific parameter. Alternately, you can simply provide the session id yourself in the call to the session() method.
If you're using Mason, you should probably take a look at MasonX::Request::WithApacheSession first, which integrates this module directly into Mason. iykyk
πΈ METHODS πΈ
This class provides the following public methods:
newβ This method creates a newApache::Session::Wrapperobject. If the parameters you provide are not correct (wrong type, missing parameters, etc.), this method throws anApache::Session::Wrapper::Exception::Paramsexception. You can treat this exception as a string if you want. β¨sessionβ This method returns a hash tied to theApache::Sessionclass. This method accepts an optionalsession_idparameter.delete_sessionβ This method deletes the existing session from persistent storage. If you are using the built-in cookie handling, it also deletes the cookie in the browser. bye bestie π
π CONFIGURATION π
This module accepts quite a number of parameters, most of which are simply passed through to Apache::Session. For this reason, you are advised to familiarize yourself with the Apache::Session documentation before attempting to configure this module.
You can also register Apache::Session classes, or the classes used for doing the work in Apache::Session::Flex. See REGISTERING CLASSES for details. π
π Supported Classes π
The following classes are already supported and do not require registration:
Apache::Session::MySQLApache::Session::PostgresApache::Session::OracleApache::Session::InformixApache::Session::SybaseApache::Session::FileApache::Session::DB_FileApache::Session::PHPApache::Session::Flex
The following classes can be used with Apache::Session::Flex:
Apache::Session::Store::MySQLApache::Session::Store::PostgresApache::Session::Store::InformixApache::Session::Store::OracleApache::Session::Store::SybaseApache::Session::Store::FileApache::Session::Store::DB_FileApache::Session::Store::PHPApache::Session::Lock::MySQLApache::Session::Lock::FileApache::Session::Lock::NullApache::Session::Lock::SemaphoreApache::Session::Generate::MD5Apache::Session::Generate::ModUsertrackApache::Session::Serialize::StorableApache::Session::Serialize::Base64Apache::Session::Serialize::SybaseApache::Session::Serialize::UUEncodeApache::Session::Serialize::PHP
π« Generic Parameters π«
class => class nameβ The name of theApache::Sessionsubclass you would like to use. This module will load this class for you if necessary. This parameter is required. βalways_write => booleanβ If this is true, then this module will ensure thatApache::Sessionwrites the session. If it is false, the defaultApache::Sessionbehavior is used instead. This defaults to true.allow_invalid_id => booleanβ If this is true, an attempt to create a session with a session id that does not exist in the session storage will be ignored, and a new session will be created instead. If it is false, aApache::Session::Wrapper::Exception::NonExistentSessionIDexception will be thrown instead. This defaults to true.session_id => stringβ Try this session id first and use it if it exists. If the session does not exist, it will ignore this parameter and make a new session.
π Cookie-Related Parameters π
use_cookie => booleanβ If true, then this module will use one ofApache::Cookie,Apache2::CookieorCGI::Cookie(as appropriate) to set and read cookies that contain the session id. πͺcookie_name => nameβ This is the name of the cookie that this module will set. This defaults toApache-Session-Wrapper-cookie. Corresponds to theApache::Cookie-nameconstructor parameter.cookie_expires => expirationβ How long before the cookie expires. This defaults to 1 day,+1d. Corresponds to the-expiresparameter. As a special case, you can set this value tosessionto have the-expiresparameter set to undef, which gives you a cookie that expires at the end of the session.cookie_domain => domainβ This corresponds to the-domainparameter. If not given this will not be set as part of the cookie. If it is undefined, then no-domainparameter will be given.cookie_path => pathβ Corresponds to the-pathparameter. It defaults to/.cookie_secure => booleanβ Corresponds to the-secureparameter. It defaults to false.cookie_resend => booleanβ By default, this parameter is true, and the cookie will be sent for every request. If it is false, then the cookie will only be sent when the session is created. This is important as resending the cookie has the effect of updating the expiration time. important!header_object => objectβ When running outside of mod_perl, you must provide an object to which the cookie header can be added. This object must provide anerr_headers_out()orheaders_out()method. Under mod_perl 1, this will default to the object returned byApache->request(). Under mod_perl 2 we callApache2::RequestUtil->request().
π¦ Query/POST-Related Parameters π¦
param_name => nameβ If set, then this module will first look for the session id in the object specified viaparam_object. This parameter determines the name of the parameter that is checked. If you are also using cookies, then the module checks the param object first, and then it checks for a cookie.param_object => objectβ This should be an object that provides aparam()method. This object will be checked to see if it contains the parameter named inparams_name. This object will probably be aCGI.pmorApache::Requestobject, but it doesn't have to be.
π Apache::Session-related Parameters π
These parameters are simply passed through to Apache::Session.
data_source => DSNβ Corresponds to theDataSourceparameter passed to the DBI-related session modules.user_name => user nameβ Corresponds to theUserNameparameter passed to the DBI-related session modules.password => passwordβ Corresponds to thePasswordparameter passed to the DBI-related session modules. Defaults to undef.handle => DBI handleβ Corresponds to theHandleparameter passed to the DBI-related session modules. This cannot be set via the httpd.conf file, because it needs to be an actual Perl variable, not the name of that variable.table_name => table nameβ Corresponds to theTableNameparameter passed to DBI-related modules.lock_data_source => DSNβ Corresponds to theLockDataSourceparameter passed toApache::Session::MySQL.lock_user_name => user nameβ Corresponds to theLockUserNameparameter passed toApache::Session::MySQL.lock_password => passwordβ Corresponds to theLockPasswordparameter passed toApache::Session::MySQL. Defaults to undef.lock_handle => DBI handleβ Corresponds to theLockHandleparameter passed to the DBI-related session modules. As with thehandleparameter, this cannot be set via the httpd.conf file.commit => booleanβ Corresponds to theCommitparameter passed to the DBI-related session modules.transaction => booleanβ Corresponds to theTransactionparameter.directory => directoryβ Corresponds to theDirectoryparameter passed toApache::Session::File.lock_directory => directoryβ Corresponds to theLockDirectoryparameter passed toApache::Session::File.file_name => file nameβ Corresponds to theFileNameparameter passed toApache::Session::DB_File.store => classβ Corresponds to theStoreparameter passed toApache::Session::Flex.lock => classβ Corresponds to theLockparameter passed toApache::Session::Flex.generate => classβ Corresponds to theGenerateparameter passed toApache::Session::Flex.serialize => classβ Corresponds to theSerializeparameter passed toApache::Session::Flex.textsize => sizeβ Corresponds to thetextsizeparameter passed toApache::Session::Sybase.long_read_len => sizeβ Corresponds to theLongReadLenparameter passed toApache::Session::MySQL.n_sems => numberβ Corresponds to theNSemsparameter passed toApache::Session::Lock::Semaphore.semaphore_key => keyβ Corresponds to theSemaphoreKeyparameter passed toApache::Session::Lock::Semaphore.mod_usertrack_cookie_name => nameβ Corresponds to theModUsertrackCookieNameparameter passed toApache::Session::Generate::ModUsertrack.save_path => pathβ Corresponds to theSavePathparameter passed toApache::Session::PHP.
πͺ HOW COOKIES ARE HANDLED πͺ
okay so bestie, when this thing runs under mod_perl, it's gonna try to use Apache::Cookie first for all the cookie-handling. if that's not available? it falls back to CGI::Cookie. no cap.
if it ends up using CGI::Cookie, then you must hand it a header_object parameter. this object has to have an err_headers_out() or headers_out() method β it checks them in that exact order. that method is supposed to return an object with an API like Apache::Table. then it calls add() on whatever comes back to slap on a Set-Cookie header. π
π REGISTERING CLASSES π
so to support any Apache::Session subclasses, this module gives you a lil registration mechanism. you can register an Apache::Session subclass, or a class that's meant to provide a class implementing something required by Apache::Session::Flex. periodt.
β¨ Registering a Complete Subclass β¨
this is done by calling Apache::Session::Wrapper->RegisterClass():
Apache::Session::Wrapper->RegisterClass
( name => 'MyClass',
required => [ [ qw( param1 param2 ) ],
[ qw( param3 param4 ) ] ],
optional => [ 'optional_p' ],
);
Apache::Session::Wrapper->RegisterClass
( name => 'Apache::Session::MyFile',
required => 'File',
optional => 'File',
);
the RegisterClass() method takes these options, bestie:
nameβ this should be the name of the class you're registering. the actual class has to start withApache::Session::, but that part doesn't need to be included when you register it (it's optional). slay.requiredβ these are the required parameters for this class. the value can either be a string or a reference to an array of array references. if it's a string, then it identifies an existingApache::Sessionsubclass that's already registered or built-in, likeFileorPostgres. if it's an array reference, then that reference should in turn contain one or more array references. each of those contained references represents one set of required parameters. when anApache::Session::Wrapperobject gets constructed, only one of these sets has to be passed in. for example:
required => [ [ qw( p1 p2 ) ],
[ qw( p2 p3 p4 ) ] ]
this says that either p1 and p2 must be provided, or p2, p3, and p4. if there are no required parameters for this class, then the required parameter can just be omitted. iconic.
optionalβ this specifies optional parameters, and it should just be a simple array reference. no biggie.
π¦ Registering a Subclass for Flex π¦
registering a subclass that can be used with Apache::Session::Flex is very similar to registering a complete class:
Apache::Session::Wrapper->RegisterFlexClass
( name => 'MyClass',
type => 'Store',
required => [ [ qw( param1 param2 ) ],
[ qw( param3 param4 ) ] ],
optional => [ 'optional_p' ],
);
Apache::Session::Wrapper->RegisterFlexClass
( name => 'Apache::Session::Store::MyFile',
type => 'store',
required => 'File',
optional => 'File',
);
the RegisterFlexClass() method has the same parameters as RegisterClass(), but it also requires a type parameter. this must be one of store, lock, generate, or serialize. iykyk. π
π SUBCLASSING π
this class provides a simple hook for subclasses. before it tries to get a session id from the URL or cookie, it calls a method named _get_session_id(). in this class, that method is a total no-op, but you can override it in a subclass. main character energy.
this class is a Class::Container subclass, so if you accept additional constructor parameters, you should declare them via the valid_params() method. don't forget, bestie.
π SUPPORT π
as you can see by the number of parameters above, Apache::Session has way too many possibilities for me to test all of them. this means there are almost certainly bugs. π
please submit bugs to the CPAN RT system at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache%3A%3ASession%3A%3AWrapper or via email at bug-apache-session-wrapper@rt.cpan.org.
support questions can be sent to me at my email address, shown below. π«Ά
π AUTHOR π
Dave Rolsky, <autarch@urth.org>
π COPYRIGHT π
Copyright (c) 2003-2006 David Rolsky. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
the full text of the license can be found in the LICENSE file included with this module.
π and that's the whole vibe, bestie β this page is from perl v5.34.0, dated 2022-06-06, and it's Apache...rapper(3pm). stay slay. β¨
π¦ where this page comes from
- debian bookworm: libapache-session-wrapper-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libapache-session-wrapper-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libapache-session-wrapper-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libapache-session-wrapper-perl 0.34-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libapache-session-wrapper-perl 0.34-4 Β· 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