perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philip M. Gollucci" <pgollu...@p6m7g8.com>
Subject Re: Apache::Session Documentation
Date Sat, 09 Dec 2006 01:30:28 GMT
Walter Vargas wrote:
> Please I need o good Documentation Project about Apache::Session Module,
> and Mod_Perl 2 in general. 
perldoc Apache::Session

-- theres nothing specific relating to mod_perl2 that different from 
mod_perl1 relating to this particular module.

startup.pl:
[snipped]
## CORE PERL Modules
use strict;
use warnings FATAL => 'all';
use Carp;

## Core MP2 Modules
use mod_perl2;
use Apache2::Const -compile =>
	qw(OK REDIRECT FORBIDDEN DECLINED HTTP_UNAUTHORIZED);
use ModPerl::MethodLookup ();

ModPerl::MethodLookup::preload_all_modules();

use Apache2::Status ();
use Apache::DBI ();
#$Apache::DBI::DEBUG = 2;

## Libapreqq
use APR::Request ();
use APR::Request::Apache2 ();
use APR::Request::CGI ();
use APR::Request::Cookie ();
use APR::Request::Error ();
use APR::Request::Hook ();
use APR::Request::Param ();
use APR::Request::Parser ();
use Apache2::Upload ();
use Apache2::Request ();
use Apache2::Cookie ();

## CPAN
use Apache::Session ();
use Apache::Session::MySQL ();
use DBI ();

## libs
use My::Foo ();
use My::Const ();

Apache::DBI->connect_on_init(
   $My::Const::dsn, $My::Const::user,
   $My::Const::pass, \%My::Const::attrs
);

1;
=---=

My/Foo.pm:
package My::Foo;
#mp2
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK);

#libapreq
use APR::Request ();
use APR::Request::Apache2 ();
use APR::Request::Cookie ();

#cpan
use Apache::Session::MySQL ();

#mine
use My::Const ();
use My::Util ();

sub handler {
   my $r = shift;

   my $req = APR::Request::Apache2->handle($r);

   my $dbh = My::Util->get_session_dbh();

   # Session Tracking -- make a new one
   tie my %session, 'Apache::Session::MySQL', undef, {
     Handle     => $dbh,
     LockHandle => $dbh
   };

   $session{time} = time();
   $session{X} = 'Y';

   my $cookie =
       APR::Request::Cookie->new(
         $r->pool,
         name   => My::Const::SESSION_CCOKIE_NAME,
         value  => $session{_session_id},
         path   => MY::Const::URL_BASE,
         domain => My::Const::COOKIE_DOMAIN,
         expires => "+10y",
       );

   $r->err_headers_out->add('Set-Cookie' => $cookie->as_string);

   # XXX ......

   return Apache2::Const::OK;
}

1;
=---=

My/Later.pm:
packate My::Later;

#core
use strict;
use warnings FATAL => 'all'; no warnings qw(redefine);
use Carp;

#mp2
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK);

#libapreq
use Apache2::Cookie ();

#cpan
use Apache::Session::MySQL ();
use DBI ();

#mine
use My::Const ();
use My::Util ();

sub handler {
   my $r = shift;

   my $jar = Apache2::Cookie::Jar->new($r);

   my $session_cookie = $jar->cookies(My::Const::SESSION_COOKIE_NAME);

   my $dbh = My::Util->get_session_dbh();

   my $session_id = $session_cookie->value;
   tie my %session, 'Apache::Session::MySQL', $session_id, {
       Handle     => $dbh,
       LockHandle => $dbh,
    };

    # XXXX .........

    return Apache2::Const::OK;
}

1;
=---=

in mysql:
show create table sessions \G
*************************** 1. row ***************************
        Table: sessions
Create Table: CREATE TABLE `sessions` (
   `id` char(32) NOT NULL,
   `a_session` text,
   PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.08 sec)

HTH

------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF

I never had a dream come true
'Til the day that I found you.
Even though I pretend that I've moved on
You'll always be my baby.
I never found the words to say
You're the one I think about each day
And I know no matter where life takes me to
A part of me will always be...
A part of me will always be with you.

Mime
View raw message