Add a session to the mason request object
In your httpd.conf file:
PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession PerlSetVar MasonSessionCookieDomain .example.com PerlSetVar MasonSessionClass Apache::Session::File PerlSetVar MasonSessionDirectory /tmp/sessions/data PerlSetVar MasonSessionLockDirectory /tmp/sessions/locks
Or when creating an ApacheHandler object:
my $ah = HTML::Mason::ApacheHandler->new ( request_class => 'MasonX::Request::WithApacheSession', session_cookie_domain => '.example.com', session_class => 'Apache::Session::File', session_directory => '/tmp/sessions/data', session_lock_directory => '/tmp/sessions/locks', );
In a component:
$m->session->{foo} = 1; if ( $m->session->{bar}{baz} > 1 ) { ... }
This module integrates \*(C`Apache::Session\*(C' into Mason by adding methods to the Mason Request object available in all Mason components.
Any subrequests created by a request share the same session.
To use this module you need to tell Mason to use this class for requests. This can be done in one of two ways. If you are configuring Mason via your httpd.conf file, simply add this:
PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession
If you are using a handler.pl file, simply add this parameter to the parameters given to the ApacheHandler constructor:
request_class => 'MasonX::Request::WithApacheSession'
This class adds two methods to the Request object.
session This method returns a hash tied to the \*(C`Apache::Session\*(C' class.
delete_session This method deletes the existing session from persistent storage. If you are using the built-in cookie mechanism, it also deletes the cookie in the browser.
This module accepts quite a number of parameters, most of which are simply passed through to \*(C`Apache::Session::Wrapper\*(C'. For this reason, you are advised to familiarize yourself with the \*(C`Apache::Session::Wrapper\*(C' documentation before attempting to configure this module.
If you are creating your own Interp/ApacheHandler/CGIHandler object in a script or module, you should pass this object the parameters intended for \*(C`Apache::Session::Wrapper\*(C', prefixed with \*(L"session_\*(R". So to set the \*(L"class\*(R" parameter for \*(C`Apache::Session::Wrapper\*(C', you pass in a \*(L"session_class\*(R" parameter.
If you are configuring Mason via your httpd.conf file, you should pass the \*(L"StudlyCaps\*(R" version of the name, prefixed by \*(L"MasonSession\*(R". So the \*(L"class\*(R" parameter would be \*(L"MasonSessionClass\*(R".
A few examples:
class becomes session_class / MasonSessionClass
always_write becomes session_always_write / MasonSessionAlwaysWrite
When running under ApacheHandler or CGIHandler, this module takes care of passing the \*(L"header_object\*(R" and \*(L"param_object\*(R" parameters to \*(C`Apache::Session::Wrapper\*(C'. These will be the \*(C`Apache::Request\*(C' or \*(C`CGI.pm\*(C' objects, as applicable.
The \*(L"cookie_name\*(R" parameter defaults to \*(L"MasonX-Request-WithApacheSession-cookie\*(R" when you use this module, instead of \*(L"Apache-Session-Wrapper-cookie\*(R".
Finally, for backwards compatiblity, this module accepts a \*(L"session_args_param\*(R" parameter, which corresponds to the \*(L"param_name\*(R" parameter for \*(C`Apache::Session::Wrapper\*(C'.
As can be seen by the number of parameters above, \*(C`Apache::Session\*(C' has way too many possibilities for me to test all of them. This means there are almost certainly bugs.
Bug reports and requests for help should be sent to the mason-users list. See http://www.masonhq.com/resources/mailing_lists.html for more details.
Dave Rolsky, <[email protected]>
HTML::Mason