File Coverage

blib/lib/Apache/Session/SharedMem.pm
Criterion Covered Total %
statement 39 45 86.6
branch n/a
condition n/a
subroutine 11 12 91.6
pod 0 2 0.0
total 50 59 84.7


line stmt bran cond sub pod time code
1             # Apache::Session::SharedMem
2              
3             # Copyright 2004 Simon Wistow
4             # This module is free software; you can redistribute it and/or
5             # modify it under the same terms as Perl itself.
6              
7              
8             package Apache::Session::SharedMem;
9              
10 1     1   237911 use strict;
  1         4  
  1         46  
11 1     1   6 use vars qw(@ISA $VERSION);
  1         2  
  1         64  
12              
13 1     1   1015 use IPC::Cache;
  1         23459  
  1         34  
14 1     1   1214 use Apache::Session;
  1         1960  
  1         31  
15 1     1   954 use Apache::Session::Lock::Null;
  1         441  
  1         29  
16 1     1   2064 use Apache::Session::Store::SharedMem;
  1         4  
  1         29  
17 1     1   1037 use Apache::Session::Generate::MD5;
  1         387  
  1         29  
18 1     1   889 use Apache::Session::Serialize::Storable;
  1         236  
  1         51  
19              
20             @ISA = qw(Apache::Session);
21             $VERSION = '0.6';
22              
23 1     1   7 use Apache::Session;
  1         2  
  1         319  
24              
25              
26             @ISA = qw(Apache::Session);
27              
28              
29             sub populate {
30 2     2 0 260 my ($self) = @_;
31              
32              
33 2         19 $self->{object_store} = new Apache::Session::Store::SharedMem $self;
34 2         15 $self->{lock_manager} = new Apache::Session::Lock::Null $self;
35 2         15 $self->{generate} = \&Apache::Session::Generate::MD5::generate;
36 2         6 $self->{validate} = \&Apache::Session::Generate::MD5::validate;
37 2         6 $self->{serialize} = \&Apache::Session::Serialize::Storable::serialize;
38 2         5 $self->{unserialize} = \&Apache::Session::Serialize::Storable::unserialize;
39              
40 2         6 return $self;
41             }
42              
43             sub DESTROY {
44 2     2   361 my $self = shift;
45            
46 2         8 $self->save;
47 2         128 $self->{object_store}->close;
48 2         12 $self->release_all_locks;
49             }
50              
51              
52             sub new
53             {
54 0     0 0   my ($class, $session) = shift;
55            
56 0           my ($self, $cacheargs);
57            
58              
59 0           $cacheargs->{namespace} = $session->{data}->{_session_id};
60 0           $cacheargs->{expires_in} = $session->{args}->{expires_in};
61              
62 0           $self->{cache} = new IPC::Cache ( $cacheargs );
63            
64 0           return bless $self, $class;
65             }
66              
67              
68             1;
69              
70             =head1 NAME
71              
72             Apache::Session::SharedMem - Session management via shared memory
73              
74             =head1 SYNOPSIS
75              
76             use Apache::Session::SharedMem;
77              
78             tie %s, 'Apache::Session::SharedMem', $sessionid, { expires_in => 86400 }
79              
80             =head1 DESCRIPTION
81              
82             This module is an implementation of Apache::Session. It uses B
83             to store session variables in shared memory.
84              
85             The advantage of this is that it is fairly fast (about the same speed, if
86             not faster than B and is very easy to set up
87             making it perfect for when you want to test sessions but can't be bothered
88             to set up a database or don't want cgi scripts writing temp files.
89              
90             =head2 CAVEATS
91              
92             It probably isn't very scaleable (i.e you probably shouldn't use this in
93             production code which is going to get hit hard.
94              
95             I have no idea if it leaks memory yet. I've only just written it :)
96              
97             Apparently it B (and hence B) don't work under Perl 5.6.
98              
99             =head1 USAGE
100              
101             Just the same as all the other B modules. You can optionally
102             pass the parameter B which will tell the Session to expire in
103             a certain time.
104              
105              
106             =head1 PREREQUISITES
107              
108             B needs B and B, both available from the CPAN.
109              
110             =head1 AUTHOR
111              
112             Simon Wistow
113              
114             =head1 COPYRIGHT
115              
116             This software is copyright(c) 2000, 2001, 2002 Simon Wistow. It is free software
117             and can be used under the same terms as perl, i.e. either the GNU
118             Public Licence or the Artistic License.
119              
120             =head1 SEE ALSO
121              
122             L, L
123              
124             =cut
125