File Coverage

blib/lib/Dancer2/Session/PSGI.pm
Criterion Covered Total %
statement 14 15 93.3
branch 4 4 100.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 23 26 88.4


line stmt bran cond sub pod time code
1             package Dancer2::Session::PSGI;
2              
3             # ABSTRACT: Dancer2 session storage via Plack::Middleware::Session
4              
5 2     2   1713 use Moo;
  2         2  
  2         13  
6             with 'Dancer2::Core::Role::SessionFactory';
7              
8             our $VERSION = '0.008'; # VERSION
9              
10             #-----------------------------------------#
11             # Alter SessionFactory attribute defaults
12             #-----------------------------------------#
13              
14             has '+cookie_name' => ( default => 'plack_session' );
15              
16             #-----------------------------------------#
17             # SessionFactory implementation methods
18             #-----------------------------------------#
19              
20             # Get middleware session hash
21             sub _retrieve {
22 6     6   58794 shift->request->env->{'psgix.session'};
23             }
24              
25             # Put data back/into middleware session hash
26             sub _flush {
27 8     8   209409 my ( $self, $id, $data ) = @_;
28 8         57 $self->request->env->{'psgix.session'} = $data;
29             }
30              
31             # Middleware handles cookie expiry
32 1     1   1802 sub _destroy { return }
33              
34             # Its the responsibility of Plack::Middleware::Session for
35             # tracking other sessions (we know nothing about them).
36             # So return an empty list.
37 0     0   0 sub _sessions { return [] }
38              
39             #-----------------------------------------#
40             # Overridden methods from SessionFactory
41             #-----------------------------------------#
42              
43             # Middleware sets the cookie.
44             sub set_cookie_header {
45 9     9 0 9246 my ( $self, %params ) = @_;
46              
47 9         21 my $session = $params{session};
48 9         33 my $options = $self->request->env->{'psgix.session.options'};
49              
50 9 100       119 if ( my $expires = $session->expires ) {
51 2 100       43 if ( $session->expires < time ) { # Cookie has expired.
52 1         15 $options->{expire} = 1;
53             }
54             else { # Pass upstream the cookie expire time
55 1         13 $options->{expires} = $expires;
56             }
57             }
58             }
59              
60             1;
61              
62             __END__