| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 37 | 1036 | $_response = $_[1]; | |||||||||||||||||||
| 38 | }else{ | ||||||||||||||||||||
| 39 | 3472 | ▶ | $_response = Dancer::Response->new() if !defined $_response; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
MC/DC0%0/2
$_timer ||= "Dancer::Timer"->new
$_timer
"Dancer::Timer"->new
Truth table66%2/3
A ||= B
A= $_timerB= "Dancer::Timer"->new
| |||||||||||||||||||||
| 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'}
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'}
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 519 | Dancer::Factory::Hook->execute_hooks('on_reset_state', $is_forward); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 519 | ▶ | if (!$is_forward) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||