Dave Rolsky > Apache-Session-Wrapper-0.33 > Apache::Session::Wrapper

Download:
Apache-Session-Wrapper-0.33.tar.gz

Dependencies

Annotate this POD (1)

CPAN RT

Open  1
View Bugs
Report a bug
Module Version: 0.33   Source   Latest Release: Apache-Session-Wrapper-0.33_01

NAME ^

Apache::Session::Wrapper - A simple wrapper around Apache::Session

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 uses 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.

METHODS ^

This class provides the following public methods:

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:

The following classes can be used with Apache::Session::Flex:

Generic Parameters

Cookie-Related Parameters

Query/POST-Related Parameters

Apache::Session-related Parameters

These parameters are simply passed through to Apache::Session.

HOW COOKIES ARE HANDLED ^

When run under mod_perl, this module attempts to first use Apache::Cookie for cookie-handling. Otherwise it uses CGI::Cookie as a fallback.

If it ends up using CGI::Cookie then you must provide a "header_object" parameter. This object must have an err_headers_out() or headers_out() method. It looks for these methods in that order. The method is expected to return an object with an API like Apache::Table. It calls add() on the returned method to add a "Set-Cookie" header.

REGISTERING CLASSES ^

In order to support any Apache::Session subclasses, this module provides a simple registration mechanism.

You can register an Apache::Session subclass, or a class intended to provide a class that implements something required by Apache::Session::Flex.

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 the following options:

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".

SUBCLASSING ^

This class provides a simple hook for subclasses. Before trying 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 no-op, but you can override this in a subclass.

This class is a Class::Container subclass, so if you accept additional constructor parameters, you should declare them via the valid_params() method.

SUPPORT ^

As can be seen 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.