Apache/JAF/Session.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 62 CC 4 SCAR 23.0
CC
4
Cov
0%
new
20.0
list
2.0
BEGIN
2.0
CRAP 10.0
1 package Apache::JAF::Session;
2
3 use DBI ();
4 use Apache ();
5 use Apache::Cookie ();
6 use Apache::Session::MySQL ();
7
8 our @ISA = qw(Apache::Session::MySQL);
9 our $FIXUP = { Columns => {} };
10
11 sub new {
12 my ($class, $expire, @dsn) = @_;
13 my $dbh = DBI->connect(@dsn);
14 my $self = { };
15
16 my %cookies = Apache::Cookie->fetch();
17 my $id = $cookies{SESSION_ID} && $cookies{SESSION_ID}->value();
18 my $t = time();
19
20 my $expired = $dbh->selectall_arrayref(q{select id from sessions where ? - unix_timestamp(modified) > ?}, $FIXUP, $t, $expire);
21 foreach (@$expired) {
22 tie %$_, $class, $_->{id}, { Handle => $dbh, LockHandle => $dbh };
23 tied(%$_)->on_end($_) if tied(%$_)->can('on_end');
24 tied(%$_)->delete();
25 }
26
27 $id = $dbh->selectrow_array(q{select id from sessions where id = ?}, undef, $id);
28 tie %$self, $class, $id, { Handle => $dbh, LockHandle => $dbh };
29 $self->{active} = $t;
30 tied(%$self)->on_start($self) if !$id && tied(%$self)->can('on_start');
31 Apache::Cookie->new(Apache->request, name => 'SESSION_ID', value => $self->{_session_id})->bake() unless $id;
32
33 return bless $self, $class;
34 }
35
36 sub list {
37 my ($self, @dsn) = @_;
38 my $dbh = DBI->connect(@dsn);
39 my $sessions = $dbh->selectall_arrayref(q{select id from sessions}, $FIXUP);
40 foreach (@$sessions) {
41 tie %{$_}, ref $self, $_->{id}, { Handle => $dbh, LockHandle => $dbh };
42 }
43 return $sessions;
44 }
45
46 1;