File Coverage

blib/lib/Dancer2/Session/Simple.pm
Criterion Covered Total %
statement 20 23 86.9
branch 2 2 100.0
condition n/a
subroutine 7 8 87.5
pod n/a
total 29 33 87.8


line stmt bran cond sub pod time code
1             package Dancer2::Session::Simple;
2             # ABSTRACT: in-memory session backend for Dancer2
3             $Dancer2::Session::Simple::VERSION = '2.0.1';
4 120     120   832006 use Moo;
  120         12482  
  120         1038  
5 120     120   60291 use Dancer2::Core::Types;
  120         601  
  120         1833  
6 120     120   1916048 use Carp;
  120         312  
  120         52674  
7              
8             with 'Dancer2::Core::Role::SessionFactory';
9              
10             # The singleton that contains all the session objects created
11             my $SESSIONS = {};
12              
13             sub _sessions {
14 0     0   0 my ($self) = @_;
15 0         0 return [ keys %{$SESSIONS} ];
  0         0  
16             }
17              
18             sub _retrieve {
19 29     29   83 my ( $class, $id ) = @_;
20 29         97 my $s = $SESSIONS->{$id};
21              
22 29 100       378 croak "Invalid session ID: $id"
23             if !defined $s;
24              
25 28         135 return $s;
26             }
27              
28             sub _change_id {
29 2     2   6 my ( $class, $old_id, $new_id ) = @_;
30              
31 2         8 $SESSIONS->{$new_id} = $class->_retrieve($old_id);
32 2         8 delete $SESSIONS->{$old_id};
33             }
34              
35             sub _destroy {
36 7     7   21 my ( $class, $id ) = @_;
37 7         25 delete $SESSIONS->{$id};
38             }
39              
40             sub _flush {
41 10062     10062   25017 my ( $class, $id, $data ) = @_;
42 10062         48813 $SESSIONS->{$id} = $data;
43             }
44              
45             1;
46              
47             __END__