blib/lib/Dancer/Plugin/WindowSession.pm

filter: Statementstmt 44.8% 26 / 58 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod n/a totaltotal 38.1% 32 / 84 CC 8 SCAR 27.7
CC
8
Cov
36%
_get_window_session_object
42.0
__ANON__
12.0
__ANON__
2.0
CRAP 15.9
↑ Summary
1 package Dancer::Plugin::WindowSession;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Clone;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.02';
9  
10 2 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub _get_window_session_object
14 0 ▶{
Subroutine _get_window_session_object: not called CC=6 SCAR=37.4
15 0 my $win_sess_id ; ## The window session ID, from the HTTP request.
16 my $win_sess_obj ; ## The Dancer::Session::Abstract object
17  
18 ## Is there a cached version of the window-session object ?
19 0 ▶ if (defined(var 'window_session_object')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined var("window_session_object")) 0 0 0
20 0 $win_sess_obj = var 'window_session_object';
21 0 $win_sess_id = $win_sess_obj->id;
22 0 return $win_sess_obj;
23 }
24  
25  
26 # This is the first time 'window_session' is request during this request handling,
27 # check if we have one in the HTTP Request
28 0 $win_sess_id = param 'winsid';
29  
30 0 ▶ my $session_engine = engine 'session'
Branch: 1 branch
BranchTrueFalseTotal
my $session_engine = engine("session") or die "Can't find session engine" 0 0 0
31 or die "Can't find session engine";
32  
33 # If we have a Window-session-Id, try to retrieve the corresponding hash.
34 0 ▶ if ($win_sess_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($win_sess_id) 0 0 0
35 0 $win_sess_obj = $session_engine->retrieve($win_sess_id);
36  
37 ## If we failed to retrieve existing window-session, force a new one
38 0 ▶ $win_sess_id = undef unless $win_sess_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $win_sess_obj 0 0 0
39 }
40  
41 # If anything failed along the way, just create a new window session
42 0 ▶ if (!$win_sess_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($win_sess_id) 0 0 0
43 0 $win_sess_obj = $session_engine->create();
44 0 $win_sess_id = $win_sess_obj->id;
45  
46 }
47 ## Cache the new window-session object,
48 ## for other route handlers downstream in the current request handling.
49 0 var 'window_session_object' => $win_sess_obj;
50  
51 0 return $win_sess_obj;
52 }
53  
54 0 ▶hook before => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 my $window_session = _get_window_session_object;
56 0 my $window_session_id = $window_session->id;
57 2 };
58  
59 0 ▶hook before_template_render => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 my $tokens = shift ;
61  
62 0 my $window_session = _get_window_session_object;
63  
64 0 $tokens->{winsid} = $window_session->id;
65 0 $tokens->{window_session} = Clone::clone($window_session);
66 2 };
67  
68 0 ▶hook after => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 my $window_session = _get_window_session_object;
70 0 my $window_session_id = $window_session->id;
71 0 $window_session->flush();
72 2 };
73  
74 0 ▶register window_session_id => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 my $window_session = _get_window_session_object;
76 0 return $window_session->id;
77 2 };
78  
79  
80 0 ▶register window_session => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
81 0 my $window_session = _get_window_session_object;
82 0 my $window_session_id = $window_session->id;
83  
84 0 my ($key,$value) = @_;
85 0 ▶ $key eq 'id' and croak 'Can\'t store to window_session key with name "id"';
Branch: 1 branch
BranchTrueFalseTotal
$key eq "id" and croak("Can't store to window_session key with name \"id\"") 0 0 0
86  
87 0 ▶ $window_session->{$key} = $value if (@_==2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 0 0 0
88 0 return $window_session->{$key};
89 2 };
90  
91 2 register_plugin;
92  
93 # ABSTRACT: A Dancer plugin for managing Browser Window Sessions
94  
95 2 1;
96 __END__
↑ Summary