SharedMem.pm

filter: Statementstmt 87.7% 43 / 49 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 2 totaltotal 85.7% 54 / 63 CC 1 SCAR 0.8
CC
1
Cov
88%
new
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Store/SharedMem.pm ↑ Summary
1 # Apache::Session::SharedMem
2  
3 # Copyright 2004 Simon Wistow <simon@thegestalt.org>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use IPC::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Apache::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Apache::Session::Lock::Null;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Apache::Session::Store::SharedMem;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Apache::Session::Generate::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Apache::Session::Serialize::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 @ISA = qw(Apache::Session);
21 1 $VERSION = '0.6';
22  
23 1 ▶use Apache::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 1 @ISA = qw(Apache::Session);
27  
28  
29 2 ▶sub populate {
Subroutine populate: called CC=1 SCAR=0.0
Pod undocumented
30 2 my ($self) = @_;
31  
32  
33 2 $self->{object_store} = new Apache::Session::Store::SharedMem $self;
34 2 $self->{lock_manager} = new Apache::Session::Lock::Null $self;
35 2 $self->{generate} = \&Apache::Session::Generate::MD5::generate;
36 2 $self->{validate} = \&Apache::Session::Generate::MD5::validate;
37 2 $self->{serialize} = \&Apache::Session::Serialize::Storable::serialize;
38 2 $self->{unserialize} = \&Apache::Session::Serialize::Storable::unserialize;
39  
40 2 return $self;
41 }
42  
43 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
44 2 my $self = shift;
45
46 2 $self->save;
47 2 $self->{object_store}->close;
48 2 $self->release_all_locks;
49 }
50  
51  
52 sub new
53 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
54 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 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<IPC::Cache>
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<Apache::Session::File> 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<IPC::ShareLite> (and hence B<IPC::Cache>) don't work under Perl 5.6.
98  
99 =head1 USAGE
100  
101 Just the same as all the other B<Apache::Session> modules. You can optionally
102 pass the parameter B<expires_in> which will tell the Session to expire in
103 a certain time.
104  
105  
106 =head1 PREREQUISITES
107  
108 B<Apache::Session::SharedMem> needs B<Apache::Session> and B<IPC:Cache>, both available from the CPAN.
109  
110 =head1 AUTHOR
111  
112 Simon Wistow <simon@twoshortplanks.com>
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<Apache::Session>, L<IPC::Cache>
123  
124 =cut
125  
« Store/SharedMem.pm ↑ Summary