blib/lib/Dancer/Session.pm

filter: Statementstmt 100% 50 / 50 Branchbran 75.0% 12 / 16 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 6 totaltotal 89.0% 81 / 91 SCAR 24.0
CC
11
Cov
94%
get_current_session
7.0
write
4.2
read
2.0
CRAP 11.0
« blib/lib/Dancer/Object.pm ↑ Summary blib/lib/Dancer/Config/Object.pm »
1 package Dancer::Session;
2 201 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: session engine for the Dancer framework
4 201 $Dancer::Session::VERSION = '1.3520';
5 201 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 201 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 201 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 201 ▶use Dancer::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 201 ▶use Dancer::Engine;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Singleton representing the session engine class to use
13 201 my $ENGINE = undef;
14 485 ▶sub engine {$ENGINE}
Subroutine engine: called CC=1 SCAR=0.0
Pod undocumented
15  
16 # This wrapper look for the session engine and try to load it.
17 sub init {
18 97 ▶ my ($class, $name, $config) = @_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
19 97 $ENGINE = Dancer::Engine->build(session => $name, $config);
20  
21 #$ENGINE->init(); already done
22 }
23  
24 # retrieve or create a session for the client
25 sub get_current_session {
26 177 ▶ shift;
Subroutine get_current_session: called CC=7 SCAR=19.5
Pod undocumented
27 177 my %p = @_;
28 177 my $sid = engine->read_session_id;
29 177 my $session = undef;
30 177 my $class = ref(engine);
31  
32 177 ▶ my $sessions = Dancer::SharedData->sessions || {};
Condition100%2/2
'Dancer::SharedData'->sessions || {}
l!l
8493
MC/DC100%1/1
'Dancer::SharedData'->sessions || {}
'Dancer::SharedData'->sessions
Truth table100%2/2
A
A= 'Dancer::SharedData'->sessions
Aresult
11
00
33 177 my $name = $class->session_name();
34 177 ▶ if ($sid and $session = $sessions->{$name}{$sid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sid and $session = $sessions->{$name}{$sid}) 80 97 177
Condition100%3/3
$sid and $session = $sessions->{$name}{$sid}
!ll&&!rl&&r
346380
MC/DC100%2/2
$sid and $session = $sessions->{$name}{$sid}
$sid $session = $sessions->{$name}{$sid}
Truth table100%3/3
A and B
A= $sidB= $session = $sessions->{$name}{$sid}
ABresult
0X0
100
111
35 80 return $session;
36 }
37
38 97 ▶ $session = $class->retrieve($sid) if $sid;
Branch: 1 branch
BranchTrueFalseTotal
if $sid 63 34 97
39  
40 97 ▶ if (not defined $session) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $session) 34 63 97
41 34 $session = $class->create();
42 }
43  
44 97 $sessions->{$name}{$session->id} = $session;
45 97 Dancer::SharedData->sessions($sessions);
46  
47 # Generate a session cookie; we want to do this regardless of whether the
48 # session is new or existing, so that the cookie expiry is updated.
49 engine->write_session_id($session->id)
50 97 ▶ unless $p{no_update};
Branch: 1 branch
BranchTrueFalseTotal
unless $p{"no_update"} 96 1 97
51  
52 97 return $session;
53 }
54  
55 132 ▶sub get { get_current_session(@_) }
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
56  
57 sub read {
58 8 ▶ my ($class, $key) = @_;
Subroutine read: called CC=2 SCAR=7.0
Pod undocumented
59 8 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 8 8
60 8 my $session = get_current_session();
61 8 return $session->get_value($key);
62 }
63  
64 sub write {
65 8 ▶ my ($class, $key, $value) = @_;
Subroutine write: called CC=4 SCAR=14.3
Pod undocumented
66  
67 8 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 8 8
68 8 ▶ $key eq 'id' and croak 'Can\'t store to session key with name "id"';
Branch: 1 branch
BranchTrueFalseTotal
$key eq "id" and croak("Can't store to session key with name \"id\"") 0 8 8
69  
70 8 my $session = get_current_session();
71 8 $session->set_value($key, $value);
72  
73 # TODO : should be moved as an "after" filter
74 8 ▶ $session->flush unless $session->is_lazy;
Branch: 1 branch
BranchTrueFalseTotal
unless $session->is_lazy 8 0 8
75 8 return $value;
76 }
77  
78 201 1;
79  
80 __END__
« blib/lib/Dancer/Object.pm ↑ Summary blib/lib/Dancer/Config/Object.pm »