Apache-Session-Wrapper

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


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

Changes  view on Meta::CPAN

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

Changes  view on Meta::CPAN


- 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

lib/Apache/Session/Wrapper.pm  view on Meta::CPAN

}

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

lib/Apache/Session/Wrapper.pm  view on Meta::CPAN


    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} };
    }

lib/Apache/Session/Wrapper.pm  view on Meta::CPAN


    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};

lib/Apache/Session/Wrapper.pm  view on Meta::CPAN


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<Apache::Cookie>,
C<Apache2::Cookie> or C<CGI::Cookie> (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<Apache::Cookie> "-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.

lib/Apache/Session/Wrapper.pm  view on Meta::CPAN

Corresponds to the C<NSems> parameter passed to
C<Apache::Session::Lock::Semaphore>.

=item * semaphore_key  =>  key

Corresponds to the C<SemaphoreKey> parameter passed to
C<Apache::Session::Lock::Semaphore>.

=item * mod_usertrack_cookie_name  =>  name

Corresponds to the C<ModUsertrackCookieName> parameter passed to
C<Apache::Session::Generate::ModUsertrack>.

=item * save_path  =>  path

Corresponds to the C<SavePath> parameter passed to
C<Apache::Session::PHP>.

=back

=head1 HOW COOKIES ARE HANDLED

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

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

=head1 REGISTERING CLASSES

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

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

t/response/TestApache/basic.pm  view on Meta::CPAN


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';
    }



( run in 0.517 second using v1.01-cache-2.11-cpan-4e96b696675 )