Apache/AxKit/Plugins/Session.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 97 CC 10 SCAR 40.1
CC
10
Cov
0%
handler
90.0
tieHash
6.0
BEGIN
2.0
CRAP 55.3
1 package Apache::AxKit::Plugins::Session;
2 use Apache::Session::Flex;
3 use Apache::Request;
4 use constant DEBUG => 0;
5 use lib qw( $VERSION %session );
6  
7 $VERSION = 0.11;
8  
9 sub handler
10 {
11 my $r = Apache::Request->instance(shift);
12  
13 # Session handling code
14 %session = ();
15 my $no_cookie = 0;
16 my $opts = {};
17  
18 # Load the configuration parameters
19 my $cfgDataStore = $r->dir_config( 'SessionDataStore' );
20 my $cfgLock = $r->dir_config( 'SessionLock' );
21 my $cfgGenerate = $r->dir_config( 'SessionGenerate' );
22 my $cfgSerialize = $r->dir_config( 'SessionSerialize' );
23  
24 my %flex_options =
25 (
26 Store => $cfgDataStore || 'DB_File',
27 Lock => $cfgLock || 'Null',
28 Generate => $cfgGenerate || 'MD5',
29 Serialize => $cfgSerialize || 'Storable'
30 );
31  
32 # Load session-type specific parameters
33 foreach my $arg ( split( /\s*,\s*/, $r->dir_config( 'SessionArgs' ) ) )
34 {
35 my ($key, $value) = split( /\s*=>\s*/, $arg );
36 $flex_options{$key} = $value;
37 }
38  
39 # Read in the cookie if this is an old session
40 my $cookie = $r->header_in('Cookie');
41 {
42 # eliminate logging of Apache::Session warn messages
43 local $^W = 0;
44  
45 $cookie =~ s/SESSION_ID=(\w*)/$1/;
46 if ( $cookie ) {
47 print STDERR "Loading existing session: \"$cookie\"\n" if DEBUG;
48 my $res = tieHash( $cookie, \%flex_options );
49 print STDERR "The tie returned $res\n" if DEBUG and $res;
50 }
51 unless ( $session{_session_id} )
52 {
53 print STDERR "Creating a new session, since \"$session{_session_id}\" didn't work.\n" if DEBUG;
54 my $res = tieHash( undef, \%flex_options );
55 $no_cookie = 1;
56 }
57 }
58  
59 # Might be a new session, so lets give them a cookie
60 if (!defined($cookie) || $no_cookie)
61 {
62 my $session_cookie = "SESSION_ID=$session{_session_id}";
63 $r->header_out("Set-Cookie" => $session_cookie);
64 $session{_creation_time} = time;
65 print STDERR "Set a new header for the session cookie: \"$session_cookie\"\n" if DEBUG;
66 }
67  
68 # Update the "Last Accessed" timestamp key
69 $session{_last_accessed_time} = time;
70  
71 # This is to try using the pnotes table, passing as a ref
72 $r->pnotes( xsp_session => \%session );
73 $r->pnotes( xsp_session_ref => tied %session );
74 print STDERR "Successfully set the session object in the pnotes table\n" if DEBUG;
75 return OK;
76 }
77  
78 sub tieHash
79 {
80 my ( $id, $options ) = @_;
81 eval
82 {
83 tie %session, 'Apache::Session::Flex', $id, $options;
84 };
85 return $@ if ( $@ );
86 }
87  
88 1;
89  
90 __END__