Apache-Session-Wrapper-0.34/0000755000175000017500000000000011375260367016066 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/META.yml0000644000175000017500000000125411375260367017341 0ustar demerphqdemerphq--- #YAML:1.0 name: Apache-Session-Wrapper version: 0.34 abstract: ~ author: [] license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Apache::Session: 1.81 Class::Container: 0 Exception::Class: 0 File::Spec: 0 File::Temp: 0 Module::Build: 0 Params::Validate: 0.7 Scalar::Util: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Apache-Session-Wrapper-0.34/Makefile.PL0000644000175000017500000000143711264073231020032 0ustar demerphqdemerphq# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Apache::Session::Wrapper', 'VERSION_FROM' => 'lib/Apache/Session/Wrapper.pm', 'PREREQ_PM' => { 'Apache::Session' => '1.81', 'Class::Container' => '0', 'Exception::Class' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'Module::Build' => '0', 'Params::Validate' => '0.7', 'Scalar::Util' => '0' }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Apache-Session-Wrapper-0.34/SIGNATURE0000644000175000017500000000313211264073231017336 0ustar demerphqdemerphqThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.54. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 863c6a514a547bcfbdab61bf3bc8fd07db1535c3 Build.PL SHA1 5cb7b8b61d3202e61f4f909fda32c24919399c37 Changes SHA1 f235ba4160673bcb7c9d58c2f09dbc7fc0efadea LICENSE SHA1 4d184ceee71ce918d464e8b8ec173c0c9ce430ae MANIFEST SHA1 26a211d44c0328f11ae84bdcf6e36d1b7f2197da META.yml SHA1 e13c6f91a330d6057ded680bfb12c067ebaa1c1e Makefile.PL SHA1 b081931e783c93cb74e2943300e87ff0f0833da4 README SHA1 c0726fd607ede8a0192cf3e0484d1cc1d23ca466 lib/Apache/Session/Wrapper.pm SHA1 a9822734d9754c39b2fb7798acce8cfd9b9b61d6 t/01-basic.t SHA1 91754573ee0fce9249ef22f571f34d850304de6a t/02-register.t SHA1 157c4c93c5a1b2325a244c54aa71f790b7addbe5 t/99-pod.t SHA1 11e74ab5027643aa27b4abe6a04414f1e91d84f8 t/TEST.PL SHA1 fdf3ec189d9ef686fc1162aaded3c20f666092fb t/apache/basic.t SHA1 456e0e788ff705db632199c3b1dc061466248d36 t/conf/extra.conf.in SHA1 c2655e02dfb348757a22180cc0f449e17c460c6f t/response/TestApache/basic.pm -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFFGTdT3Or3ZzQuifMRAtvNAKCzAoGur7SgoTNwVKoBkLzJfqiYBwCfQIH8 UGQ+3UduZWnKPwUdom95aeI= =o1QG -----END PGP SIGNATURE----- Apache-Session-Wrapper-0.34/lib/0000755000175000017500000000000011375260367016634 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/lib/Apache/0000755000175000017500000000000011375260367020015 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/lib/Apache/Session/0000755000175000017500000000000011375260367021440 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/lib/Apache/Session/Wrapper.pm0000644000175000017500000010571211375257260023422 0ustar demerphqdemerphqpackage Apache::Session::Wrapper; use strict; use vars qw($VERSION); $VERSION = '0.34'; $VERSION = eval $VERSION; use base qw(Class::Container); use Apache::Session 1.81; use Exception::Class ( 'Apache::Session::Wrapper::Exception::NonExistentSessionID' => { description => 'A non-existent session id was used', fields => [ 'session_id' ] }, 'Apache::Session::Wrapper::Exception::Params' => { description => 'An invalid parameter or set of parameters was given', alias => 'param_error' }, ); use Params::Validate 0.70; use Params::Validate qw( validate SCALAR UNDEF BOOLEAN ARRAYREF OBJECT ); Params::Validate::validation_options( on_fail => sub { param_error( join '', @_ ) } ); use Scalar::Util (); my $MOD_PERL = _find_mp_version(); sub _find_mp_version { return 0 unless $ENV{MOD_PERL}; return ( $ENV{MOD_PERL} =~ /(?:1\.9|2\.\d)/ ? 2 : 1 ); } my @HeaderMethods = qw( err_headers_out headers_out ); my %params = ( always_write => { type => BOOLEAN, default => 1, descr => 'Whether or not to force a write before the session goes out of scope' }, allow_invalid_id => { type => BOOLEAN, default => 1, descr => 'Whether or not to allow a failure to find an existing session id' }, param_name => { type => SCALAR, optional => 1, depends => 'param_object', descr => 'Name of the parameter to use for session tracking' }, param_object => { type => OBJECT, optional => 1, can => 'param', descr => 'Object which has a "param" method, to be used for getting the session id from a query string or POST argument' }, use_cookie => { type => BOOLEAN, default => 0, descr => 'Whether or not to use a cookie to track the session' }, cookie_name => { type => SCALAR, default => 'Apache-Session-Wrapper-cookie', descr => 'Name of cookie used by this module' }, cookie_expires => { type => UNDEF | SCALAR, default => '+1d', descr => 'Expiration time for cookies' }, cookie_domain => { type => UNDEF | SCALAR, optional => 1, descr => 'Domain parameter for cookies' }, cookie_path => { type => SCALAR, default => '/', descr => 'Path for cookies' }, cookie_secure => { type => BOOLEAN, default => 0, descr => 'Are cookies sent only for SSL connections?' }, cookie_resend => { type => BOOLEAN, default => 1, descr => 'Resend the cookie on each request?' }, header_object => { type => OBJECT, callbacks => { 'has a method to set headers' => sub { grep { $_[0]->can($_) } @HeaderMethods } }, optional => 1, descr => 'An object that can be used to send cookies with' }, class => { type => SCALAR, descr => 'An Apache::Session class to use for sessions' }, data_source => { type => SCALAR, optional => 1, descr => 'The data source when using MySQL or PostgreSQL' }, user_name => { type => UNDEF | SCALAR, optional => 1, descr => 'The user name to be used when connecting to a database' }, password => { type => UNDEF | SCALAR, default => undef, descr => 'The password to be used when connecting to a database' }, table_name => { type => UNDEF | SCALAR, optional => 1, descr => 'The table in which sessions are saved' }, lock_data_source => { type => SCALAR, optional => 1, descr => 'The data source when using MySQL or PostgreSQL' }, lock_user_name => { type => UNDEF | SCALAR, optional => 1, descr => 'The user name to be used when connecting to a database' }, lock_password => { type => UNDEF | SCALAR, default => undef, descr => 'The password to be used when connecting to a database' }, handle => { type => OBJECT, optional => 1, descr => 'An existing database handle to use' }, lock_handle => { type => OBJECT, optional => 1, descr => 'An existing database handle to use' }, commit => { type => BOOLEAN, default => 1, descr => 'Whether or not to auto-commit changes to the database' }, transaction => { type => BOOLEAN, default => 0, descr => 'The Transaction flag for Apache::Session' }, directory => { type => SCALAR, optional => 1, descr => 'A directory to use when storing sessions' }, lock_directory => { type => SCALAR, optional => 1, descr => 'A directory to use for locking when storing sessions' }, file_name => { type => SCALAR, optional => 1, descr => 'A DB_File to use' }, store => { type => SCALAR, optional => 1, descr => 'A storage class to use with the Flex module' }, lock => { type => SCALAR, optional => 1, descr => 'A locking class to use with the Flex module' }, generate => { type => SCALAR, default => 'MD5', descr => 'A session generator class to use with the Flex module' }, serialize => { type => SCALAR, optional => 1, descr => 'A serialization class to use with the Flex module' }, textsize => { type => SCALAR, optional => 1, descr => 'A parameter for the Sybase storage module' }, long_read_len => { type => SCALAR, optional => 1, descr => 'A parameter for the Oracle storage module' }, n_sems => { type => SCALAR, optional => 1, descr => 'A parameter for the Semaphore locking module' }, semaphore_key => { type => SCALAR, optional => 1, descr => 'A parameter for the Semaphore locking module' }, mod_usertrack_cookie_name => { type => SCALAR, optional => 1, descr => 'The cookie name used by mod_usertrack' }, save_path => { type => SCALAR, optional => 1, descr => 'Path used by Apache::Session::PHP' }, session_id => { type => SCALAR, optional => 1, descr => 'Try this session id first when making a session' }, ); # What set of parameters are required for each session class. # Multiple array refs represent multiple possible sets of parameters my %ApacheSessionParams = ( Flex => [ [ qw( store lock generate serialize ) ] ], MySQL => [ [ qw( data_source user_name lock_data_source lock_user_name ) ], [ qw( handle lock_handle ) ] ], Postgres => [ [ qw( data_source user_name commit ) ], [ qw( handle commit ) ] ], File => [ [ qw( directory lock_directory ) ] ], DB_File => [ [ qw( file_name lock_directory ) ] ], PHP => [ [ qw( save_path ) ] ], ); @ApacheSessionParams{ qw( Informix Oracle Sybase ) } = ( $ApacheSessionParams{Postgres} ) x 3; my %OptionalApacheSessionParams = ( MySQL => [ [ qw( table_name password lock_password ) ] ], Postgres => [ [ qw( table_name password ) ] ], Informix => [ [ qw( table_name password ) ] ], Oracle => [ [ qw( long_read_len table_name password ) ] ], Sybase => [ [ qw( textsize table_name password ) ] ], ); my %ApacheSessionFlexParams = ( store => { MySQL => [ [ qw( data_source user_name ) ], [ qw( handle ) ] ], Postgres => $ApacheSessionParams{Postgres}, File => [ [ qw( directory ) ] ], DB_File => [ [ qw( file_name ) ] ], PHP => $ApacheSessionParams{PHP}, }, lock => { MySQL => [ [ qw( lock_data_source lock_user_name ) ], [ qw( lock_handle ) ] ], File => [ [ ] ], Null => [ [ ] ], Semaphore => [ [ ] ], }, generate => { MD5 => [ [ ] ], ModUniqueId => [ [ ] ], ModUsertrack => [ [ qw( mod_usertrack_cookie_name ) ] ], }, serialize => { Storable => [ [ ] ], Base64 => [ [ ] ], Sybase => [ [ ] ], UUEncode => [ [ ] ], PHP => [ [ ] ], }, ); @{ $ApacheSessionFlexParams{store} }{ qw( Informix Oracle Sybase ) } = ( $ApacheSessionFlexParams{store}{Postgres} ) x 3; my %OptionalApacheSessionFlexParams = ( store => { map { $_ => $OptionalApacheSessionParams{$_} } qw( MySQL Postgres Informix Oracle Sybase ) }, ); sub _SetValidParams { my $class = shift; my %extra; for my $hash ( \%ApacheSessionParams, \%OptionalApacheSessionParams, @ApacheSessionFlexParams{ qw( store lock generate serialize ) }, @OptionalApacheSessionFlexParams{ qw( store lock generate serialize ) }, ) { for my $p ( map { @$_ } map { @$_ } values %$hash ) { my $h; if ( ref $p ) { # we assume its a hash of names/parameter specifications $h = $p; } elsif (!$params{$p}) { # its a new parameter defined by a scalar, default to SCALAR value $h = { $p => { optional => 1, type => SCALAR } }; } else { # its a scalar option we already know. next; } # now expand the options foreach my $name (keys %$h) { next if $params{$name}; $extra{$p} = $h->{$name}; } } } $class->valid_params( %extra, %params ); $class->SetStudlyForms(); } __PACKAGE__->_SetValidParams(); my %StudlyForm; sub SetStudlyForms { %StudlyForm = ( map { $_ => _studly_form($_) } map { ref $_ ? @$_ :$_ } map { @$_ } ( values %ApacheSessionParams ), ( values %OptionalApacheSessionParams ), ( map { values %{ $ApacheSessionFlexParams{$_} } } keys %ApacheSessionFlexParams ), ( map { values %{ $OptionalApacheSessionFlexParams{$_} } } keys %OptionalApacheSessionFlexParams ), ); # why Apache::Session does this I do not know $StudlyForm{textsize} = 'textsize'; } sub _studly_form { my $string = shift; $string =~ s/(?:^|_)(\w)/\U$1/g; return $string; } sub RegisterClass { my $class = shift; my %p = validate( @_, { name => { type => SCALAR }, required => { type => SCALAR | ARRAYREF, default => [ [ ] ] }, optional => { type => SCALAR | ARRAYREF, default => [ ] }, }, ); $p{name} =~ s/^Apache::Session:://; $ApacheSessionParams{ $p{name} } = ( ref $p{required} ? $p{required} : $ApacheSessionParams{ $p{required} } ); $OptionalApacheSessionParams{ $p{name} } = ( ref $p{optional} ? [ $p{optional} ] : $OptionalApacheSessionParams{ $p{optional} } ); $class->_SetValidParams(); } sub RegisterFlexClass { my $class = shift; my %p = validate( @_, { type => { type => SCALAR, regex => qr/^(?:store|lock|generate|serialize)/, }, name => { type => SCALAR }, required => { type => SCALAR | ARRAYREF, default => [ [ ] ] }, optional => { type => SCALAR | ARRAYREF, default => [ ] }, }, ); $p{name} =~ s/^Apache::Session:://; $p{name} =~ s/^\Q$p{type}\E:://i; $ApacheSessionFlexParams{ $p{type} }{ $p{name} } = ( ref $p{required} ? $p{required} : $ApacheSessionFlexParams{ $p{type} }{ $p{required} } ); $OptionalApacheSessionFlexParams{ $p{type} }{ $p{name} } = ( ref $p{optional} ? [ $p{optional} ] : $OptionalApacheSessionFlexParams{ $p{type} }{ $p{optional} } ); $class->_SetValidParams(); } sub new { my $class = shift; my %p = @_; my $self = $class->SUPER::new(%p); $self->_check_session_params; $self->_set_session_params; if ( $self->{use_cookie} && ! ( $ENV{MOD_PERL} || $self->{header_object} ) ) { param_error "The header_object parameter is required in order to use cookies outside of mod_perl"; } my $session_class = "Apache::Session::$self->{session_class_piece}"; unless ( $session_class->can('TIEHASH') ) { eval "require $session_class"; die $@ if $@; } $self->_make_session( $p{session_id} ); $self->_bake_cookie if $self->{use_cookie} && ! $self->{cookie_is_baked}; return $self; } sub _check_session_params { my $self = shift; $self->{session_class_piece} = $self->{class}; $self->{session_class_piece} =~ s/^Apache::Session:://; my $sets = $ApacheSessionParams{ $self->{session_class_piece} } or param_error "Invalid session class: $self->{class}"; $self->_check_sets( $sets, 'session', $self->{class} ) if grep { @$_ } @$sets; if ( $self->{session_class_piece} eq 'Flex' ) { foreach my $key ( keys %ApacheSessionFlexParams ) { my $subclass = $self->{$key}; my $sets = $ApacheSessionFlexParams{$key}{$subclass} or param_error "Invalid class for $key: $self->{$key}"; $self->_check_sets( $sets, $key, $subclass ) if grep { @$_ } @$sets; } } } sub _check_sets { my $self = shift; my $sets = shift; my $type = shift; my $class = shift; my @missing; foreach my $set (@$sets) { my @matched = grep { exists $self->{$_} } @$set; return if @matched == @$set; @missing = grep { ! exists $self->{$_} } @$set; } param_error "Some or all of the required parameters for your chosen $type class ($class) were provided." . " The following parameters were missing: @missing\n"; } sub _set_session_params { my $self = shift; my %params; $self->_sets_to_params ( $ApacheSessionParams{ $self->{session_class_piece} }, \%params ); $self->_sets_to_params ( $OptionalApacheSessionParams{ $self->{session_class_piece} }, \%params ); if ( $self->{session_class_piece} eq 'Flex' ) { foreach my $key ( keys %ApacheSessionFlexParams ) { my $subclass = $self->{$key}; $params{ $StudlyForm{$key} } = $subclass; $self->_sets_to_params ( $ApacheSessionFlexParams{$key}{$subclass}, \%params ); $self->_sets_to_params ( $OptionalApacheSessionFlexParams{$key}{$subclass}, \%params ); } } $self->{params} = \%params; $self->_set_cookie_fields if $self->{use_cookie}; } sub _set_cookie_fields { my $self = shift; my $cookie_class; if ($MOD_PERL) { $cookie_class = $MOD_PERL == 2 ? 'Apache2::Cookie' : 'Apache::Cookie'; eval "require $cookie_class" unless $cookie_class->can('new'); } unless ( $cookie_class && $cookie_class->can('new' ) ) { require CGI::Cookie; $cookie_class = 'CGI::Cookie'; } $self->{cookie_class} = $cookie_class; if ( $self->{cookie_class} eq 'CGI::Cookie' ) { $self->{new_cookie_args} = []; $self->{fetch_cookie_args} = []; } else { $self->{new_cookie_args} = [ $MOD_PERL == 2 ? Apache2::RequestUtil->request : Apache->request ]; $self->{fetch_cookie_args} = ( $MOD_PERL == 2 ? $self->{new_cookie_args} : [] ); $self->{bake_cookie_args} = ( $MOD_PERL == 2 ? $self->{new_cookie_args} : [] ); } } sub _sets_to_params { my $self = shift; my $sets = shift; my $params = shift; foreach my $set (@$sets) { foreach my $key (@$set) { if ( exists $self->{$key} ) { $params->{ $StudlyForm{$key} } = $self->{$key}; } } } } sub _make_session { my $self = shift; my $session_id = shift; return if defined $session_id && $self->_try_session_id( $session_id ); my $id = $self->_get_session_id; return if defined $id && $self->_try_session_id($id); if ( defined $self->{param_name} ) { my $id = $self->_get_session_id_from_args; return if defined $id && $self->_try_session_id($id); } if ( $self->{use_cookie} ) { my $id = $self->_get_session_id_from_cookie; if ( defined $id && $self->_try_session_id($id) ) { $self->{cookie_is_baked} = 1 unless $self->{cookie_resend}; return; } } # make a new session id $self->_try_session_id(undef); } # for subclasses sub _get_session_id { return } sub _get_session_id_from_args { my $self = shift; return $self->{param_object}->param( $self->{param_name} ); } sub _get_session_id_from_cookie { my $self = shift; if ( $MOD_PERL == 2 ) { my $jar = Apache2::Cookie::Jar->new( @{ $self->{fetch_cookie_args} } ); my $c = $jar->cookies( $self->{cookie_name} ); return $c->value if $c; } else { my %c = $self->{cookie_class}->fetch( @{ $self->{fetch_cookie_args} } ); return $c{ $self->{cookie_name} }->value if exists $c{ $self->{cookie_name} }; } return undef; } sub _try_session_id { my $self = shift; my $session_id = shift; return 1 if ( $self->{session} && defined $session_id && $self->{session_id} eq $session_id ); my %s; { local $SIG{__DIE__}; eval { tie %s, "Apache::Session::$self->{session_class_piece}", $session_id, $self->{params}; }; if ( $@ || ! tied %s || ! $s{_session_id} ) { $self->_handle_tie_error( $@, $session_id ); return; } } untie %{ $self->{session} } if $self->{session}; $self->{session} = \%s; $self->{session_id} = $s{_session_id}; $self->{cookie_is_baked} = 0; return 1; } sub _handle_tie_error { my $self = shift; my $err = shift; my $session_id = shift; if ( $err =~ /Object does not exist/ && defined $session_id ) { return if $self->{allow_invalid_id}; Apache::Session::Wrapper::Exception::NonExistentSessionID->throw ( error => "Invalid session id: $session_id", session_id => $session_id ); } else { my $error = $err ? $err : "Tying to Apache::Session::$self->{session_class_piece} failed but did not throw an exception"; die $error; } } sub _bake_cookie { my $self = shift; my $expires = shift || $self->{cookie_expires}; $expires = undef if defined $expires && $expires =~ /^session$/i; my $domain = $self->{cookie_domain}; my $cookie = $self->{cookie_class}->new ( @{ $self->{new_cookie_args} }, -name => $self->{cookie_name}, # Apache2::Cookie will return undef if we pass undef for # -value. -value => ( $self->{session_id} || '' ), ( defined $expires ? ( -expires => $expires ) : () ), ( defined $domain ? ( -domain => $domain ) : () ), -path => $self->{cookie_path}, -secure => $self->{cookie_secure}, ); # If not running under mod_perl, CGI::Cookie->bake() will call # print() to send a cookie header right now, which may not be what # the user wants. if ( $cookie->can('bake') && ! $cookie->isa('CGI::Cookie') ) { $cookie->bake( @{ $self->{bake_cookie_args} } ); } else { my $header_object = $self->{header_object}; for my $meth (@HeaderMethods) { if ( $header_object->can($meth) ) { $header_object->$meth->add( 'Set-Cookie' => $cookie ); last; } } } # always set this even if we skipped actually setting the cookie # to avoid resending it. this keeps us from entering this method # over and over $self->{cookie_is_baked} = 1 unless $self->{cookie_resend}; } sub session { my $self = shift; my %p = validate( @_, { session_id => { type => SCALAR, optional => 1, }, } ); if ( ! $self->{session} || %p ) { $self->_make_session( $p{session_id} ); $self->_bake_cookie if $self->{use_cookie} && ! $self->{cookie_is_baked}; } return $self->{session}; } sub delete_session { my $self = shift; return unless $self->{session}; my $session = delete $self->{session}; (tied %$session)->delete; delete $self->{session_id}; $self->_bake_cookie('-1d') if $self->{use_cookie}; } sub cleanup_session { my $self = shift; if ( $self->{always_write} ) { if ( $self->{session}->{___force_a_write___} ) { $self->{session}{___force_a_write___} = 0; } else { $self->{session}{___force_a_write___} = 1; } } undef $self->{session}; } sub DESTROY { $_[0]->cleanup_session } 1; __END__ =head1 NAME Apache::Session::Wrapper - A simple wrapper around Apache::Session =head1 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; =head1 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 C method. If you're using Mason, you should probably take a look at C first, which integrates this module directly into Mason. =head1 METHODS This class provides the following public methods: =over 4 =item * new This method creates a new C object. If the parameters you provide are not correct (wrong type, missing parameters, etc.), this method throws an C exception. You can treat this exception as a string if you want. =item * session This method returns a hash tied to the C class. This method accepts an optional "session_id" parameter. =item * 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. =back =head1 CONFIGURATION This module accepts quite a number of parameters, most of which are simply passed through to C. For this reason, you are advised to familiarize yourself with the C documentation before attempting to configure this module. You can also register C classes, or the classes used for doing the work in C. See L for details. =head2 Supported Classes The following classes are already supported and do not require registration: =over 4 =item * Apache::Session::MySQL =item * Apache::Session::Postgres =item * Apache::Session::Oracle =item * Apache::Session::Informix =item * Apache::Session::Sybase =item * Apache::Session::File =item * Apache::Session::DB_File =item * Apache::Session::PHP =item * Apache::Session::Flex =back The following classes can be used with C: =over 4 =item * Apache::Session::Store::MySQL =item * Apache::Session::Store::Postgres =item * Apache::Session::Store::Informix =item * Apache::Session::Store::Oracle =item * Apache::Session::Store::Sybase =item * Apache::Session::Store::File =item * Apache::Session::Store::DB_File =item * Apache::Session::Store::PHP =item * Apache::Session::Lock::MySQL =item * Apache::Session::Lock::File =item * Apache::Session::Lock::Null =item * Apache::Session::Lock::Semaphore =item * Apache::Session::Generate::MD5 =item * Apache::Session::Generate::ModUsertrack =item * Apache::Session::Serialize::Storable =item * Apache::Session::Serialize::Base64 =item * Apache::Session::Serialize::Sybase =item * Apache::Session::Serialize::UUEncode =item * Apache::Session::Serialize::PHP =back =head2 Generic Parameters =over 4 =item * class => class name The name of the C subclass you would like to use. This module will load this class for you if necessary. This parameter is required. =item * always_write => boolean If this is true, then this module will ensure that C writes the session. If it is false, the default C behavior is used instead. This defaults to true. =item * 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, a C exception will be thrown instead. This defaults to true. =item * session_id => string Try this session id first and use it if it exist. If the session does not exist, it will ignore this parameter and make a new session. =back =head2 Cookie-Related Parameters =over 4 =item * use_cookie => boolean If true, then this module will use one of C, C or C (as appropriate) to set and read cookies that contain the session id. =item * cookie_name => name This is the name of the cookie that this module will set. This defaults to "Apache-Session-Wrapper-cookie". Corresponds to the C "-name" constructor parameter. =item * cookie_expires => expiration How long before the cookie expires. This defaults to 1 day, "+1d". Corresponds to the "-expires" parameter. As a special case, you can set this value to "session" to have the "-expires" parameter set to undef, which gives you a cookie that expires at the end of the session. =item * cookie_domain => domain This corresponds to the "-domain" parameter. If not given this will not be set as part of the cookie. If it is undefined, then no "-domain" parameter will be given. =item * cookie_path => path Corresponds to the "-path" parameter. It defaults to "/". =item * cookie_secure => boolean Corresponds to the "-secure" parameter. It defaults to false. =item * cookie_resend => boolean By default, this parameter is true, and the cookie will be sent for I. If it is false, then the cookie will only be sent when the session is I. This is important as resending the cookie has the effect of updating the expiration time. =item * 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 an C or C method. Under mod_perl 1, this will default to the object returned by C<< Apache->request() >>. Under mod_perl 2 we call C<< Apache2::RequestUtil->request() >> =back =head2 Query/POST-Related Parameters =over 4 =item * param_name => name If set, then this module will first look for the session id in the object specified via "param_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 I, and then it checks for a cookie. =item * param_object => object This should be an object that provides a C method. This object will be checked to see if it contains the parameter named in "params_name". This object will probably be a C or C object, but it doesn't have to be. =back =head2 Apache::Session-related Parameters These parameters are simply passed through to C. =over 4 =item * data_source => DSN Corresponds to the C parameter passed to the DBI-related session modules. =item * user_name => user name Corresponds to the C parameter passed to the DBI-related session modules. =item * password => password Corresponds to the C parameter passed to the DBI-related session modules. Defaults to undef. =item * handle => DBI handle Corresponds to the C parameter passed to the DBI-related session modules. This cannot be set via the F file, because it needs to be an I, not the I of that variable. =item * table_name => table name Corresponds to the C paramaeter passed to DBI-related modules. =item * lock_data_source => DSN Corresponds to the C parameter passed to C. =item * lock_user_name => user name Corresponds to the C parameter passed to C. =item * lock_password => password Corresponds to the C parameter passed to C. Defaults to undef. =item * lock_handle => DBI handle Corresponds to the C parameter passed to the DBI-related session modules. As with the C parameter, this cannot be set via the F file. =item * commit => boolean Corresponds to the C parameter passed to the DBI-related session modules. =item * transaction => boolean Corresponds to the C parameter. =item * directory => directory Corresponds to the C parameter passed to C. =item * lock_directory => directory Corresponds to the C parameter passed to C. =item * file_name => file name Corresponds to the C parameter passed to C. =item * store => class Corresponds to the C parameter passed to C. =item * lock => class Corresponds to the C parameter passed to C. =item * generate => class Corresponds to the C parameter passed to C. =item * serialize => class Corresponds to the C parameter passed to C. =item * textsize => size Corresponds to the C parameter passed to C. =item * long_read_len => size Corresponds to the C parameter passed to C. =item * n_sems => number Corresponds to the C parameter passed to C. =item * semaphore_key => key Corresponds to the C parameter passed to C. =item * mod_usertrack_cookie_name => name Corresponds to the C parameter passed to C. =item * save_path => path Corresponds to the C parameter passed to C. =back =head1 HOW COOKIES ARE HANDLED When run under mod_perl, this module attempts to first use C for cookie-handling. Otherwise it uses C as a fallback. If it ends up using C then you must provide a "header_object" parameter. This object must have an C or C method. It looks for these methods in that order. The method is expected to return an object with an API like C. It calls C on the returned method to add a "Set-Cookie" header. =head1 REGISTERING CLASSES In order to support any C subclasses, this module provides a simple registration mechanism. You can register an C subclass, or a class intended to provide a class that implements something required by C. =head2 Registering a Complete Subclass This is done by calling C<< 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 C method takes the following options: =over 4 =item * name This should be the name of the class you are registering. The actual class must start with "Apache::Session::", but this part does not need to be included when registering the class (it's optional). =item * required These are the required parameters for this class. The value of this parameter can either be a string or a reference to an array of array references. If it is a string, then it identifies an existing C subclass which is already registered or built-in, like "File" or "Postgres". If it an array reference, then I should in turn contain one or more array references. Each of those contained references represents one set of required parameters. When an C object is constructed, only one of these sets must be passed in. For example: required => [ [ qw( p1 p2 ) ], [ qw( p2 p3 p4 ) ] ] This says that either "p1" and "p2" must be provided, I "p2", "p3", and "p4". If there are no required parameters for this class, then the "required" parameter can be omitted. =item * optional This specifies optional parameters, and should just be a simple array reference. =back =head2 Registering a Subclass for Flex Registering a subclass that can be used with C 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 C method has the same parameters as C, but it also requires a "type" parameter. This must be one of "store", "lock", "generate", or "serialize". =head1 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 C<_get_session_id()>. In this class, that method is a no-op, but you can override this in a subclass. This class is a C subclass, so if you accept additional constructor parameters, you should declare them via the C method. =head1 SUPPORT As can be seen by the number of parameters above, C has B 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. =head1 AUTHOR Dave Rolsky, =head1 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. =cut Apache-Session-Wrapper-0.34/README0000644000175000017500000000044211264073231016733 0ustar demerphqdemerphqThis module provides a simple wrapper for Apache::Session that manages the session id for you. See the module documentation for details. INSTALLATION To install this module type the following in the distribution directory: perl Build.PL ./Build ./Build test ./Build install Apache-Session-Wrapper-0.34/LICENSE0000644000175000017500000005010111264073231017055 0ustar demerphqdemerphqTerms of Perl itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --------------------------------------------------------------------------- The General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS --------------------------------------------------------------------------- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Apache-Session-Wrapper-0.34/Build.PL0000644000175000017500000000167011264073231017353 0ustar demerphqdemerphquse strict; use Module::Build; my $build_pkg = eval { require Apache::TestMB; 1; } ? 'Apache::TestMB' : 'Module::Build'; my $build = $build_pkg->new ( module_name => 'Apache::Session::Wrapper', license => 'perl', sign => 1, requires => { 'Apache::Session' => 1.81, 'Class::Container' => 0, 'Exception::Class' => 0, 'Params::Validate' => 0.70, 'Scalar::Util' => 0, }, build_requires => { 'File::Spec' => 0, 'File::Temp' => 0, 'Module::Build' => 0, }, create_makefile_pl => 'traditional', ); $build->create_build_script; $build->add_to_cleanup( qw( t/session t/conf/apreq2.conf t/conf/skip ) ); Apache-Session-Wrapper-0.34/t/0000755000175000017500000000000011375260367016331 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/t/99-pod.t0000644000175000017500000000021711264073231017524 0ustar demerphqdemerphquse strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Apache-Session-Wrapper-0.34/t/01-basic.t0000644000175000017500000001163111264073231020004 0ustar demerphqdemerphq#!/usr/bin/perl -w use strict; use File::Spec; use File::Temp (); use Test::More tests => 20; use_ok('Apache::Session::Wrapper'); my %params = ( class => 'Flex', store => 'File', lock => 'Null', generate => 'MD5', serialize => 'Storable', ); $params{directory} = File::Temp::tempdir( CLEANUP => 1 ); # We do this to generate a pre-existing session id that will be used # in the tests below. use Apache::Session::Flex; my %session; tie %session, 'Apache::Session::Flex', undef, { Store => 'File', Lock => 'Null', Generate => 'MD5', Serialize => 'Storable', Directory => $params{directory}, }; $session{bar}{baz} = 1; my $id = $session{_session_id}; untie %session; { my $w = Apache::Session::Wrapper->new(%params); ok( tied %{ $w->session }, 'session is a tied thing' ); isa_ok( tied %{ $w->session }, 'Apache::Session' ); } { my $w = Apache::Session::Wrapper->new(%params); $w->session( session_id => $id )->{foo} = 'bar'; } { my $w = Apache::Session::Wrapper->new(%params); is( $w->session( session_id => $id )->{foo}, 'bar', 'stored a value in the session' ); } { my $w = Apache::Session::Wrapper->new(%params); eval { $w->session( session_id => 'abcdef' ) }; ok( ! $@, 'invalid session id is allowed by default' ); } { my $w = Apache::Session::Wrapper->new( %params, allow_invalid_id => 0 ); eval { $w->session( session_id => 'abcdef' ) }; my $e = $@; ok( $e, 'invalid session id caused an error' ); isa_ok( $e, 'Apache::Session::Wrapper::Exception::NonExistentSessionID' ); } { my $w = Apache::Session::Wrapper->new(%params); $w->session( session_id => $id )->{bar}{baz} = 50; is( $w->session( session_id => $id )->{bar}{baz}, 50, 'always write - in memory value' ); } { my $w = Apache::Session::Wrapper->new(%params); is( $w->session( session_id => $id )->{bar}{baz}, 50, 'always write - stored value' ); } { my $w = Apache::Session::Wrapper->new( %params, always_write => 0 ); $w->session( session_id => $id )->{bar}{baz} = 100; is( $w->session( session_id => $id )->{bar}{baz}, 100, 'always write is off - in memory value' ); } { my $w = Apache::Session::Wrapper->new( %params, always_write => 0 ); is( $w->session( session_id => $id )->{bar}{baz}, 50, 'always write is off - stored value' ); $w = Apache::Session::Wrapper->new( %params, session_id => $id ); is( $w->session->{_session_id}, $id, 'id matches session id given to new()' ); } { my $w = Apache::Session::Wrapper->new( %params ); $w->session( session_id => $id )->{quux} = 100; $w->delete_session; is( $w->session( session_id => $id )->{quux}, undef, 'session is empty after delete_session' ); } { no warnings 'redefine'; # so attempt to connect to MySQL doesn't happen local *Apache::Session::Wrapper::_make_session = sub {}; my $wrapper = eval { local $^W = 0; Apache::Session::Wrapper->new( class => 'Flex', store => 'MySQL', lock => 'Null', generate => 'MD5', serialize => 'Storable', data_source => 'foo', user_name => 'bar', password => 'baz', ) }; unlike( $@, qr/parameters/, 'pass correct parameters for MySQL flex' ); is( $wrapper->{params}{DataSource}, 'foo', 'DataSource is foo' ); is( $wrapper->{params}{UserName}, 'bar', 'UserName is bar' ); is( $wrapper->{params}{Password}, 'baz', 'Password is baz' ); } { eval { local $^W = 0; Apache::Session::Wrapper->new( class => 'Postgres', data_source => 'foo', user_name => 'foo', password => 'foo', commit => 0, ) }; unlike( $@, qr/parameters/, 'first param set for Pg' ); } { my $dbh = bless {}, 'DBI'; eval { local $^W = 0; Apache::Session::Wrapper->new( class => 'Postgres', handle => $dbh, commit => 0, ) }; unlike( $@, qr/parameters/, 'second param set for Pg' ); } { my $dbh = bless {}, 'DBI'; eval { Apache::Session::Wrapper->new( class => 'Postgres', commit => 0, ) }; like( $@, qr/required parameters.+missing: handle/, 'incomplete params for Pg' ); } Apache-Session-Wrapper-0.34/t/apache/0000755000175000017500000000000011375260367017552 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/t/apache/basic.t0000644000175000017500000000236611264073231021014 0ustar demerphqdemerphq#!perl -w use strict; use File::Spec; use Test::More; BEGIN { my $skip_file = File::Spec->catfile( qw( t conf skip ) ); if ( -f $skip_file ) { plan skip_all => 'You must have the apreq2 module to run these tests with apache2.'; } else { plan tests => 6; } } use Apache::Test qw(:withtestmore); use Apache::TestUtil; use Apache::TestRequest qw(GET); my $ua = Apache::TestRequest::user_agent( cookie_jar => {} ); { my $res = GET '/TestApache__basic'; ok( $res->is_success, 'request succeeded' ); ok( $res->header('set-cookie'), 'response includes cookie' ); my ($cookie_val1) = ( $res->header('set-cookie') =~ m{asw_cookie=([^;]+);} ); $res = GET '/TestApache__basic'; $res->header('set-cookie') =~ m{asw_cookie=([^;]+);}; my ($cookie_val2) = ( $res->header('set-cookie') =~ m{asw_cookie=([^;]+);} ); is( $cookie_val1, $cookie_val2, 'got the same cookie for each request' ); unlike( $res->content, qr/ERROR/, 'no error message in response' ); } { my $res = GET '/TestApache__basic?delete=1'; like( $res->header('set-cookie'), qr/asw_cookie=(?:;|\z)/, 'no value in cookie when deleting' ); unlike( $res->content, qr/ERROR/, 'no error message in response' ); } Apache-Session-Wrapper-0.34/t/TEST.PL0000644000175000017500000000300011264073231017323 0ustar demerphqdemerphq#!perl use strict; use warnings; my $runner = Apache::TestRunPerl::Custom->new()->run(@ARGV); # The custom module package Apache::TestRunPerl::Custom; use base qw(Apache::TestRunPerl); use File::Spec; use IO::File; sub configure { my $self = shift; my $conf_file = $self->_conf_file(); my $skip_file = File::Spec->catfile( $self->{test_config}{vars}{t_conf}, 'skip' ); for my $file ( $conf_file, $skip_file ) { if ( -f $file ) { unlink $file or die "Cannot unlink $file: $!"; } } $self->SUPER::configure(@_); if ( $self->{test_config}{server}{rev} >= 2 ) { my $apreq2 = $self->{test_config}->find_apache_module('mod_apreq2.so'); if ($apreq2) { $self->_write_apreq_conf( "LoadModule apreq_module $apreq2" ); } else { $self->_write_apreq_conf(''); open my $fh, '>', $skip_file or die "Cannot write to $skip_file: $!"; } } else { $self->_write_apreq_conf(''); } } sub _conf_file { File::Spec->catfile( $_[0]->{test_config}{vars}{t_conf}, 'apreq2.conf' ) } sub _write_apreq_conf { my $self = shift; my $content = shift; my $conf_file = $self->_conf_file(); open my $fh, '>', $conf_file or die "Cannot write to $conf_file: $!"; print $fh $content . "\n" or die "Cannot write to $conf_file: $!"; close $fh or die "Cannot write to $conf_file: $!"; } 1; Apache-Session-Wrapper-0.34/t/02-register.t0000644000175000017500000001126511264073231020553 0ustar demerphqdemerphq#!/usr/bin/perl -w use strict; use File::Temp (); use Test::More tests => 10; use Apache::Session::Wrapper; my $tempdir = File::Temp::tempdir( CLEANUP => 1 ); { { package Apache::Session::FooBar; use base 'Apache::Session::File'; } # Passing the full name with Apache::Session:: prefix makes sure # we can handle that. Apache::Session::Wrapper->RegisterClass ( name => 'Apache::Session::FooBar', required => 'File', ); eval { Apache::Session::Wrapper->new ( class => 'FooBar', directory => $tempdir, lock_directory => $tempdir, ) }; is( $@, '', 'made a new wrapper using FooBar class' ); eval { Apache::Session::Wrapper->new( class => 'FooBar' ) }; like( $@, qr/required parameters.+missing: directory/, 'incomplete params for FooBar' ); } { { package Apache::Session::Baz; use base 'Apache::Session::File'; } Apache::Session::Wrapper->RegisterClass( name => 'Baz', required => [ [ 'thing' ] ], optional => [ 'foo' ], ); eval { Apache::Session::Wrapper->new( class => 'Baz', thing => 1, ) }; is( $@, '', 'made a new wrapper using Baz class' ); eval { Apache::Session::Wrapper->new( class => 'Baz', thing => 1, foo => 27, ) }; is( $@, '', 'made a new wrapper using Baz class with optional param' ); eval { Apache::Session::Wrapper->new( class => 'Baz' ) }; like( $@, qr/required parameters.+missing: thing/, 'incomplete params for Baz' ); eval { Apache::Session::Wrapper->new( class => 'Baz', thing => 1, bar => 5, ) }; like( $@, qr/following parameter/, 'extra invalid param for Baz' ); } { { package Apache::Session::Quux; use base 'Apache::Session::File'; } # Tests multiple valid sets of required params. Apache::Session::Wrapper->RegisterClass( name => 'Quux', required => [ [ 'thing1', 'thing2' ], [ 'kitty' ], ], ); eval { Apache::Session::Wrapper->new( class => 'Quux', thing1 => 1, thing2 => 1, ) }; is( $@, '', 'made a new wrapper using Quux class' ); eval { Apache::Session::Wrapper->new( class => 'Quux', kitty => 'Hello', ) }; is( $@, '', 'made a new wrapper using Quux class' ); eval { Apache::Session::Wrapper->new( class => 'Quux', thing1 => 1, ) }; like( $@, qr/some or all/i, 'missing required params for Quux' ); } { { package Apache::Session::Store::Dummy; use base 'Apache::Session::Store::File'; } { package Apache::Session::Generate::Dummy; use Apache::Session::Generate::MD5; # double assignment prevents a "used only once" warning *Apache::Session::Generate::Dummy::generate = *Apache::Session::Generate::Dummy::generate = \&Apache::Session::Generate::MD5::generate; *Apache::Session::Generate::Dummy::validate = *Apache::Session::Generate::Dummy::validate = \&Apache::Session::Generate::MD5::validate; } Apache::Session::Wrapper->RegisterFlexClass ( name => 'Apache::Session::Store::Dummy', type => 'store', required => [ [ 'size' ] ], ); Apache::Session::Wrapper->RegisterFlexClass ( name => 'Generate::Dummy', type => 'generate', required => [ [ 'seed' ] ], optional => [ 'goo' ], ); eval { Apache::Session::Wrapper->new ( class => 'Flex', store => 'Dummy', lock => 'Null', generate => 'Dummy', serialize => 'Storable', size => 'big', seed => 'corn', ) }; is( $@, '', 'made a new Flex wrapper with Dummy store & generate' ); } Apache-Session-Wrapper-0.34/t/conf/0000755000175000017500000000000011375260367017256 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/t/conf/extra.conf.in0000644000175000017500000000024611264073231021644 0ustar demerphqdemerphq# This is the location where file-based sessions are stored PerlSetVar SessionDir @ServerRoot@/session # Get the apreq config for ModPerl2. Include conf/apreq2.conf Apache-Session-Wrapper-0.34/t/response/0000755000175000017500000000000011375260367020167 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/t/response/TestApache/0000755000175000017500000000000011375260367022210 5ustar demerphqdemerphqApache-Session-Wrapper-0.34/t/response/TestApache/basic.pm0000644000175000017500000000331211264073231023613 0ustar demerphqdemerphqpackage TestApache::basic; use strict; use warnings FATAL => 'all'; use File::Path (); my $MOD_PERL; my $REQ_CLASS; BEGIN { if ( $ENV{MOD_PERL} =~ /(?:1\.9|2\.\d)/ ) { eval <<'EOF'; use Apache2::Request; use Apache2::Cookie; use Apache2::Const qw(OK); use Apache2::RequestRec; use Apache2::RequestUtil; EOF die $@ if $@; $MOD_PERL = 2; $REQ_CLASS = 'Apache2::Request'; } else { eval <<'EOF'; use Apache::Request; use Apache::Constants qw(OK); EOF die $@ if $@; $MOD_PERL = 1; $REQ_CLASS = 'Apache::Request'; } } use Apache::Session::Wrapper; sub handler ($$) : method { my $class = shift; my $r = $REQ_CLASS->new(shift); Apache2::RequestUtil->request($r) if $MOD_PERL == 2; my $dir = $r->dir_config('SessionDir'); File::Path::mkpath( $dir, 0, 0755 ); $r->content_type('text/plain'); my $output = ''; eval { my $w = Apache::Session::Wrapper->new ( class => 'File', directory => $dir, lock_directory => $dir, use_cookie => 1, cookie_name => 'asw_cookie', cookie_expires => '10m', cookie_path => '/', cookie_resend => 1, always_write => 1, header_object => $r, ); $output .= "SESSION: " . $w->session->{_session_id} . "\n"; $w->delete_session() if $r->param('delete'); }; $output .= "ERROR: $@" if $@; $r->send_http_header if $MOD_PERL == 1; print $output; return OK; } 1; Apache-Session-Wrapper-0.34/Changes0000644000175000017500000001317111375257612017363 0ustar demerphqdemerphq0.34 2010-05-20 - Rerelease 0.33_01 as 0.34 0.33_01 2009-12-31 - Fix user defined options handling and fix default of optional options. See http://rt.cpan.org/Public/Bug/Display.html?id=49561. - Trap possibly clobbered $@. - New maintainer. 0.33 2006-09-26 - When setting up tests with Apache::Test, if the user has apache2 we need to make sure that they have the mod_apreq2.so library available. If they don't, the live tests will be skipped. Based on a patch from Derek Price. RT #21552. 0.32 2006-09-18 - Work around a (maybe) bug in Apache2::Cookie. Set -value to undef to in Apach2::Cookie->new causes it to return undef, rather than a cookie with no value. This meant that delete_session() caused an "attempt to call method of undefined value" error. Reported by Derek Price. RT #20992. 0.31 2006-07-11 - Exactly 0.30 but now the Build.PL creates a "traditional" Makefile.PL. This fixes the problem that the generated "passthrough" Makefile.PL was requiring Apache::TestMB, because it's available on my system. 0.30 2006-07-10 - Exactly like 0.29 but does not declare a "build_requires" dependency on Apache::TestMB. Declaring this dependency causes CPAN.pm (and probably CPANPLUS) to try and install Apache::Test, which may not always install cleanly. If you do have it already installed, then it will be used to run the live tests. 0.29 2006-06-09 - When not running under mod_perl, Apache::Session::Wrapper simply did not even try to load CGI::Cookie to generate cookies. Patch by Derek Poon. - When running under mod_perl 1 without Apache::Request, an exception was generated when trying to send a cookie. - Apache::Session::Wrapper now only checks for err_headers_out and headers_out on the header_object, since this works for both mod_perl 1 and 2, as well as Mason's FakeApache object. - As of version CGI.pm 3.16, CGI::Cookie has a bake() method, but now Apache::Session::Wrapper explicitly will not call it, because if you're not running under mod_perl, it ends up calling print() to send the cookie header when it is called, which may not be what a user of this module wants. Patch by Derek Poon. 0.28 2006-05-23 - Allow a session_id parameter to the constructor, to force the use of a particular existing session. - Fixed a bug where failing to create a new session was ignored if allow_invalid_id was true. - Detect very weird case where tying to tie to Apache::Session succeeds but the tied hash has no _session_id key. This now throws an exception. - Fixed bug when the header_object ->can('header_out') but this method does not return an object, as with HTML::Mason::FakeApache. Reported by Hans Dieter. - The logic to load an appropriate cookie class if the class was already loaded and an exception had previously been thrown by an unrelated class. - Added a way to register session subclass via RegisterClass() and RegisterFlexClass(), to allow people to use any session subclass they want without needing explicit support in Apache::Session::Wrapper. 0.27 not released - This was a version used internally at Socialtext, but never released. 0.26 2005-09-20 - Finally should work properly under both mp1 and mp2. Patches and tests by Daisuke Maki. - No longer depends on Apache::Cookie or Apache2::Cookie, but it will use them if it can instead of CGI::Cookie. 0.25 2005-08-14 - Silenced a warning that could occur when using session length cookies under mod_perl. 0.24 2005-08-01 - Optional parameters for store modules were not handled properly when using Flex as the session class. Added some tests. Reported by Gavin Carr. 0.23 2005-07-26 - If two sets of valid parameters for a class shared a parameter, an error would be thrown if you used the second set, even if it was complete. Reported by Victor Felix. 0.22 2005-07-18 - Another fix for mod_perl2, this one from Jonas. 0.21 2005-06-20 - The fix for mod_perl2 caused a new cookie to be sent for each request under mod_perl 1. I love it! 0.20 2005-06-08 - Fix to make getting cookies work under mod_perl2. Reported by Baldvin Kovacs. 0.19 2005-02-15 - Add support for Apache::RequestRec as header_object by checking header_object for err_headers_out and headers_out methods. 0.18 2004-06-30 - Made the password & lock_password parameters default to undef. 0.17 2004-04-23 - Fix a bug in checking parameters which could occur when the "commit" parameter for Postgres, Oracle, or Sybcase was passed. This caused a fatal error when creating the wrapper object. Patch by Max Baker. 0.16 2004-04-08 - No code changes, just include Class::Container in the dependencies. Reported via CPAN testers. 0.15 2004-04-06 - No code changes, just added the SIGNATURE file to the manifest so that signature checks don't fail. 0.14 2004-04-03 - Fix a bug which causes the constructor to complain that some required parameters were missing when in fact the required parameters had been given. Reported by Jim Mozley. 0.13 2004-03-19 - Allow the cookie expiration to be set to "session", which is equivalent to undef, and causes the cookie to expire when the browser is closed. Requested by Herald (RT #5615) for MasonX::Request::WithApacheSession. - Remove some incorrect default values for some parameters, which were being set to undef when they shouldn't be. 0.12 2004-02-26 - Document that constructor can throw an exception. - Document that session method accepts a session_id parameter. 0.11 2004-02-26 - Change default cookie name to "Apache-Session-Wrapper-cookie". - Add subclassing docs. 0.10 2004-02-26 - First release Apache-Session-Wrapper-0.34/MANIFEST0000644000175000017500000000042111264073231017201 0ustar demerphqdemerphqBuild.PL Changes lib/Apache/Session/Wrapper.pm LICENSE Makefile.PL MANIFEST This list of files META.yml README t/01-basic.t t/02-register.t t/99-pod.t t/apache/basic.t t/conf/extra.conf.in t/response/TestApache/basic.pm t/TEST.PL SIGNATURE Added here by Module::Build