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
« lib/Dancer/GetOpt.pm ↑ Summary lib/Dancer/Response.pm »
1 package Dancer::SharedData;
2 230 our $AUTHORITY = 'cpan:SUKRIA';
3 # ABSTRACT: Shared-data singleton for Dancer
4 230 $Dancer::SharedData::VERSION = '1.3522';
5 230 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 230 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 230 ▶use Dancer::Timer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 230 ▶use Dancer::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 230 ▶use Dancer::Factory::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 230 Dancer::Factory::Hook->instance->install_hooks(
12 qw/on_reset_state/
13 );
14  
15 # shared variables
16 230 my $vars = {};
17 111 ▶sub vars {$vars}
Subroutine vars: called CC=1 SCAR=0.0
Pod undocumented
18  
19 19 ▶sub var {
Subroutine var: called CC=2 SCAR=6.9
Pod undocumented
20 19 my ($class, $key, $value) = @_;
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 230 my $_headers;
27 617 ▶sub headers { (@_ == 2) ? $_headers = $_[1] : $_headers }
Subroutine headers: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 2 615 617
28  
29 # request singleton
30 my $_request;
31 4017 ▶sub request { (@_ == 2) ? $_request = $_[1] : $_request }
Subroutine request: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 545 3472 4017
32  
33 # current response
34 230 my $_response;
35 4508 ▶sub response {
Subroutine response: called CC=3 SCAR=11.0
Pod undocumented
36 4508 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 1036 3472 4508
37 1036 $_response = $_[1];
38 }else{
39 3472 ▶ $_response = Dancer::Response->new() if !defined $_response;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_response 528 2944 3472
40 3472 return $_response;
41 }
42 }
43 1018 ▶sub reset_response { $_response = undef }
Subroutine reset_response: called CC=1 SCAR=0.0
Pod undocumented
44  
45 # sessions singleton
46 230 my $_sessions;
47 274 ▶sub sessions { (@_ == 2) ? $_sessions = $_[1] : $_sessions }
Subroutine sessions: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 97 177 274
48  
49 # request timer
50 230 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 519 ▶sub reset_timer { $_timer = Dancer::Timer->new }
Subroutine reset_timer: called CC=1 SCAR=0.0
Pod undocumented
53  
54 # purging accessor
55 519 ▶sub reset_all {
Subroutine reset_all: called CC=3 SCAR=11.0
Pod undocumented
56 519 my ($self, %options) = @_;
57 519 ▶ my $is_forward = exists($options{reset_vars}) && ! $options{reset_vars};
Condition100%3/3
exists $options{'reset_vars'} && !$options{'reset_vars'}
!ll&&!rl&&r
499515
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 519 Dancer::Factory::Hook->execute_hooks('on_reset_state', $is_forward);
60  
61 519 ▶ if (!$is_forward) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_forward) 504 15 519
62 504 $vars = {};
63 }
64 519 undef $_sessions;
65 519 undef $_request;
66 519 undef $_headers;
67 519 reset_timer();
68 519 reset_response();
69 }
70  
71 230 'Dancer::SharedData';
72  
73 __END__
« lib/Dancer/GetOpt.pm ↑ Summary lib/Dancer/Response.pm »