line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ark::Plugin::Session::Backend; |
2
|
10
|
|
|
10
|
|
5316
|
use strict; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
351
|
|
3
|
10
|
|
|
10
|
|
55
|
use warnings; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
323
|
|
4
|
10
|
|
|
10
|
|
65
|
use Ark 'Component'; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
79
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has session_id => ( |
7
|
|
|
|
|
|
|
is => 'rw', |
8
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
9
|
|
|
|
|
|
|
lazy => 1, |
10
|
|
|
|
|
|
|
builder => 'get_session_id', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has session_data => ( |
14
|
|
|
|
|
|
|
is => 'rw', |
15
|
|
|
|
|
|
|
isa => 'Maybe[HashRef]', |
16
|
|
|
|
|
|
|
lazy => 1, |
17
|
|
|
|
|
|
|
default => sub { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
return unless $self->session_id; |
20
|
|
|
|
|
|
|
$self->get_session_data( $self->session_id ); |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has session_updated => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
isa => 'Bool', |
27
|
|
|
|
|
|
|
default => 0, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has uuid_model => ( |
31
|
|
|
|
|
|
|
is => 'rw', |
32
|
|
|
|
|
|
|
isa => 'Str', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has digest_model => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => 'Str', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has expire => ( |
41
|
|
|
|
|
|
|
is => "rw", |
42
|
|
|
|
|
|
|
isa => "Int", |
43
|
|
|
|
|
|
|
default => 0, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has finalized => ( |
47
|
|
|
|
|
|
|
is => 'rw', |
48
|
|
|
|
|
|
|
isa => 'Bool', |
49
|
|
|
|
|
|
|
default => 0, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
after $_ => sub { shift->session_updated(1); } |
53
|
|
|
|
|
|
|
for qw/get set remove/; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
before $_ => sub { |
56
|
|
|
|
|
|
|
die "session is already finalized. can't call set or remove method" if shift->finalized; |
57
|
|
|
|
|
|
|
} for qw/set remove/; |
58
|
|
|
|
|
|
|
|
59
|
10
|
|
|
10
|
|
84
|
no Ark; |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
57
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get { |
62
|
|
|
|
|
|
|
my ($self, $key) = @_; |
63
|
|
|
|
|
|
|
my $data = $self->session_data or return; |
64
|
|
|
|
|
|
|
$data->{ $key }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub set { |
68
|
|
|
|
|
|
|
my ($self, $key, $value) = @_; |
69
|
|
|
|
|
|
|
$self->initialize_session_data unless $self->session_data; |
70
|
|
|
|
|
|
|
$self->session_data->{ $key } = $value; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub remove { |
74
|
|
|
|
|
|
|
my ($self, $key) = @_; |
75
|
|
|
|
|
|
|
return unless $self->session_data; |
76
|
|
|
|
|
|
|
delete $self->session_data->{ $key }; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub regenerate { |
80
|
2
|
|
|
2
|
0
|
7
|
my ($self) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# ignore if session does not exists |
83
|
2
|
50
|
|
|
|
12
|
return unless $self->session_id; |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
11
|
my $session_data = $self->session_data; |
86
|
2
|
|
|
|
|
10
|
$self->remove_session_data($self->session_id); |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
6
|
$self->initialize_session_data; |
89
|
2
|
|
|
|
|
25
|
$self->set_session_data($self->session_id => $session_data); |
90
|
2
|
|
|
|
|
12
|
$self->session_data($session_data); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub initialize_session_data { |
94
|
15
|
|
|
15
|
0
|
31
|
my $self = shift; |
95
|
|
|
|
|
|
|
|
96
|
15
|
|
33
|
|
|
73
|
my $uuid = $self->uuid_model && $self->app->model( $self->uuid_model ); |
97
|
15
|
|
33
|
|
|
113
|
my $digest = $self->digest_model && $self->app->model( $self->digest_model ); |
98
|
|
|
|
|
|
|
|
99
|
15
|
50
|
|
|
|
60
|
unless ($uuid) { |
100
|
15
|
|
|
|
|
79
|
$self->ensure_class_loaded('Data::UUID'); |
101
|
15
|
|
|
|
|
7257
|
$uuid = Data::UUID->new; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
15
|
50
|
|
|
|
82
|
unless ($digest) { |
105
|
15
|
|
|
|
|
73
|
$self->ensure_class_loaded('Digest::SHA1'); |
106
|
15
|
|
|
|
|
10479
|
$digest = Digest::SHA1->new; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
15
|
|
|
|
|
2966
|
$digest->add( $uuid->create ); |
110
|
|
|
|
|
|
|
|
111
|
15
|
|
|
|
|
171
|
$self->set_session_id( $digest->hexdigest ); |
112
|
15
|
|
|
|
|
11634
|
$self->session_data({}); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# State |
116
|
|
|
|
147
|
0
|
|
sub get_session_id { } |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub set_session_id { |
119
|
17
|
|
|
17
|
0
|
48
|
my ($self, $sid) = @_; |
120
|
17
|
|
|
|
|
92
|
$self->session_id($sid); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
0
|
0
|
|
sub remove_session_id { } |
124
|
|
|
|
|
|
|
# sub extend_session_id { } |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Store |
128
|
|
|
|
3
|
0
|
|
sub get_session_data { } |
129
|
|
|
|
81
|
0
|
|
sub set_session_data { } |
130
|
|
|
|
2
|
0
|
|
sub remove_session_data { } |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub finalize_session { |
133
|
80
|
|
|
80
|
0
|
186
|
my ($self, $res) = @_; |
134
|
|
|
|
|
|
|
|
135
|
80
|
100
|
66
|
|
|
468
|
if ($self->session_updated and my $sid = $self->session_id) { |
136
|
79
|
|
|
|
|
308
|
$self->set_session_data( $sid, $self->session_data ); |
137
|
|
|
|
|
|
|
} |
138
|
80
|
|
|
|
|
379
|
$self->finalized(1); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |