blib/lib/Dancer/SharedData.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 14 / 14 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 10 totaltotal 86.6% 84 / 97 CC 10 SCAR 6.5
CC
10
Cov
99%
response
3.0
reset_all
3.0
timer
2.1
CRAP 1.9
« blib/lib/Dancer/GetOpt.pm ↑ Summary blib/lib/Dancer/Response.pm »
1 package Dancer::SharedData;
2 219 our $AUTHORITY = 'cpan:SUKRIA';
3 # ABSTRACT: Shared-data singleton for Dancer
4 219 $Dancer::SharedData::VERSION = '1.3513';
5 220 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 220 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 220 ▶use Dancer::Timer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 220 ▶use Dancer::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 219 ▶use Dancer::Factory::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 219 Dancer::Factory::Hook->instance->install_hooks(
12 qw/on_reset_state/
13 );
14  
15 # shared variables
16 219 my $vars = {};
17 111 ▶sub vars {$vars}
Subroutine vars: called CC=1 SCAR=0.0
Pod undocumented
18  
19 sub var {
20 19 ▶ my ($class, $key, $value) = @_;
Subroutine var: called CC=2 SCAR=6.9
Pod undocumented
21 19 ▶ $vars->{$key} = $value if (@_ == 3);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 15 4 19
22 19 return $vars->{$key};
23 }
24  
25 # request headers
26 219 my $_headers;
27 614 ▶sub headers { (@_ == 2) ? $_headers = $_[1] : $_headers }
Subroutine headers: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 2 612 614
28  
29 # request singleton
30 my $_request;
31 3996 ▶sub request { (@_ == 2) ? $_request = $_[1] : $_request }
Subroutine request: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 542 3454 3996
32  
33 # current response
34 219 my $_response;
35 sub response {
36 4483 ▶ if (@_ == 2) {
Subroutine response: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 1030 3453 4483
37 1030 $_response = $_[1];
38 }else{
39 3453 ▶ $_response = Dancer::Response->new() if !defined $_response;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_response 525 2928 3453
40 3453 return $_response;
41 }
42 }
43 1012 ▶sub reset_response { $_response = undef }
Subroutine reset_response: called CC=1 SCAR=0.0
Pod undocumented
44  
45 # sessions singleton
46 219 my $_sessions;
47 270 ▶sub sessions { (@_ == 2) ? $_sessions = $_[1] : $_sessions }
Subroutine sessions: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 95 175 270
48  
49 # request timer
50 219 my $_timer;
51 34 ▶sub timer { $_timer ||= Dancer::Timer->new }
Subroutine timer: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_timer ||= "Dancer::Timer"->new
l!l&&r!l&&!r
2680
MC/DC0%0/2
$_timer ||= "Dancer::Timer"->new
$_timer "Dancer::Timer"->new
Truth table66%2/3
A ||= B
A= $_timerB= "Dancer::Timer"->new
ABresult
1X1
011
000
52 516 ▶sub reset_timer { $_timer = Dancer::Timer->new }
Subroutine reset_timer: called CC=1 SCAR=0.0
Pod undocumented
53  
54 # purging accessor
55 sub reset_all {
56 516 ▶ my ($self, %options) = @_;
Subroutine reset_all: called CC=3 SCAR=11.0
Pod undocumented
57 516 ▶ my $is_forward = exists($options{reset_vars}) && ! $options{reset_vars};
Condition100%3/3
exists $options{'reset_vars'} && !$options{'reset_vars'}
!ll&&!rl&&r
496515
MC/DC100%2/2
exists $options{'reset_vars'} && !$options{'reset_vars'}
exists $options{'reset_vars'} !$options{'reset_vars'}
Truth table100%3/3
A && not(B)
A= exists $options{'reset_vars'}B= !$options{'reset_vars'}
ABresult
0X0
100
111
58  
59 516 Dancer::Factory::Hook->execute_hooks('on_reset_state', $is_forward);
60  
61 516 ▶ if (!$is_forward) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_forward) 501 15 516
62 501 $vars = {};
63 }
64 516 undef $_sessions;
65 516 undef $_request;
66 516 undef $_headers;
67 516 reset_timer();
68 516 reset_response();
69 }
70  
71 219 'Dancer::SharedData';
72  
73 __END__
« blib/lib/Dancer/GetOpt.pm ↑ Summary blib/lib/Dancer/Response.pm »