line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::SharedData; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SUKRIA'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Shared-data singleton for Dancer |
4
|
|
|
|
|
|
|
$Dancer::SharedData::VERSION = '1.3521'; |
5
|
189
|
|
|
189
|
|
1311
|
use strict; |
|
189
|
|
|
|
|
434
|
|
|
189
|
|
|
|
|
5348
|
|
6
|
189
|
|
|
189
|
|
959
|
use warnings; |
|
189
|
|
|
|
|
409
|
|
|
189
|
|
|
|
|
4525
|
|
7
|
189
|
|
|
189
|
|
79041
|
use Dancer::Timer; |
|
189
|
|
|
|
|
553
|
|
|
189
|
|
|
|
|
4877
|
|
8
|
189
|
|
|
189
|
|
81405
|
use Dancer::Response; |
|
189
|
|
|
|
|
684
|
|
|
189
|
|
|
|
|
6024
|
|
9
|
189
|
|
|
189
|
|
1408
|
use Dancer::Factory::Hook; |
|
189
|
|
|
|
|
413
|
|
|
189
|
|
|
|
|
82737
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Dancer::Factory::Hook->instance->install_hooks( |
12
|
|
|
|
|
|
|
qw/on_reset_state/ |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# shared variables |
16
|
|
|
|
|
|
|
my $vars = {}; |
17
|
111
|
|
|
111
|
0
|
278
|
sub vars {$vars} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub var { |
20
|
19
|
|
|
19
|
0
|
64
|
my ($class, $key, $value) = @_; |
21
|
19
|
100
|
|
|
|
68
|
$vars->{$key} = $value if (@_ == 3); |
22
|
19
|
|
|
|
|
50
|
return $vars->{$key}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# request headers |
26
|
|
|
|
|
|
|
my $_headers; |
27
|
613
|
100
|
|
613
|
0
|
2764
|
sub headers { (@_ == 2) ? $_headers = $_[1] : $_headers } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# request singleton |
30
|
|
|
|
|
|
|
my $_request; |
31
|
3990
|
100
|
|
3990
|
0
|
12055
|
sub request { (@_ == 2) ? $_request = $_[1] : $_request } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# current response |
34
|
|
|
|
|
|
|
my $_response; |
35
|
|
|
|
|
|
|
sub response { |
36
|
4492
|
100
|
|
4492
|
0
|
9714
|
if (@_ == 2) { |
37
|
1032
|
|
|
|
|
2846
|
$_response = $_[1]; |
38
|
|
|
|
|
|
|
}else{ |
39
|
3460
|
100
|
|
|
|
8717
|
$_response = Dancer::Response->new() if !defined $_response; |
40
|
3460
|
|
|
|
|
7974
|
return $_response; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
1016
|
|
|
1016
|
0
|
2223
|
sub reset_response { $_response = undef } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# sessions singleton |
46
|
|
|
|
|
|
|
my $_sessions; |
47
|
274
|
100
|
|
274
|
0
|
1013
|
sub sessions { (@_ == 2) ? $_sessions = $_[1] : $_sessions } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# request timer |
50
|
|
|
|
|
|
|
my $_timer; |
51
|
26
|
|
66
|
26
|
0
|
170
|
sub timer { $_timer ||= Dancer::Timer->new } |
52
|
517
|
|
|
517
|
0
|
2289
|
sub reset_timer { $_timer = Dancer::Timer->new } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# purging accessor |
55
|
|
|
|
|
|
|
sub reset_all { |
56
|
517
|
|
|
517
|
0
|
1180
|
my ($self, %options) = @_; |
57
|
517
|
|
100
|
|
|
1520
|
my $is_forward = exists($options{reset_vars}) && ! $options{reset_vars}; |
58
|
|
|
|
|
|
|
|
59
|
517
|
|
|
|
|
2443
|
Dancer::Factory::Hook->execute_hooks('on_reset_state', $is_forward); |
60
|
|
|
|
|
|
|
|
61
|
517
|
100
|
|
|
|
1366
|
if (!$is_forward) { |
62
|
502
|
|
|
|
|
1142
|
$vars = {}; |
63
|
|
|
|
|
|
|
} |
64
|
517
|
|
|
|
|
985
|
undef $_sessions; |
65
|
517
|
|
|
|
|
4172
|
undef $_request; |
66
|
517
|
|
|
|
|
10871
|
undef $_headers; |
67
|
517
|
|
|
|
|
1345
|
reset_timer(); |
68
|
517
|
|
|
|
|
1222
|
reset_response(); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
'Dancer::SharedData'; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |