line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ado::Sessions::File; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
859
|
use Mojo::Base 'Ado::Sessions'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
21
|
|
4
|
3
|
|
|
3
|
|
492
|
use Mojo::Util qw(slurp spurt b64_decode b64_encode); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
218
|
|
5
|
3
|
|
|
3
|
|
541
|
use File::Spec::Functions qw(tmpdir catfile); |
|
3
|
|
|
|
|
681
|
|
|
3
|
|
|
|
|
1287
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has dstdir => sub {tmpdir}; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub dstfile { |
10
|
10
|
|
|
10
|
1
|
138
|
my ($self, $id) = @_; |
11
|
10
|
|
|
|
|
66
|
return 'ado.' . $id; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub absfile { |
15
|
10
|
|
|
10
|
1
|
46
|
my ($self, $id) = @_; |
16
|
10
|
|
|
|
|
43
|
return catfile $self->dstdir, $self->dstfile($id); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub load { |
20
|
5
|
|
|
5
|
1
|
147
|
my ($self, $c) = @_; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
9
|
my $session = {}; |
23
|
5
|
|
100
|
|
|
24
|
my $id = $self->session_id($c) || ''; |
24
|
5
|
|
|
|
|
486
|
my $cookie_file = $self->absfile($id); |
25
|
|
|
|
|
|
|
|
26
|
5
|
100
|
66
|
|
|
104
|
if ($id and -e $cookie_file) { |
27
|
3
|
|
|
|
|
14
|
my $sessiondata = slurp $cookie_file; |
28
|
|
|
|
|
|
|
return |
29
|
3
|
50
|
|
|
|
273
|
unless $session = Mojo::JSON::j(b64_decode($sessiondata)); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
597
|
return $self->prepare_load($c, $session); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub store { |
36
|
5
|
|
|
5
|
1
|
3545
|
my ($self, $c) = @_; |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
48
|
my ($id, $session) = $self->prepare_store($c); |
39
|
5
|
|
|
|
|
26
|
my $value = b64_encode(Mojo::JSON::encode_json($session), ''); |
40
|
5
|
|
|
|
|
475
|
my $file = $self->absfile($id); |
41
|
5
|
|
|
|
|
22
|
spurt $value, $file; |
42
|
5
|
|
|
|
|
1309
|
chmod(oct('0600'), $file); |
43
|
5
|
|
|
|
|
35
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# TODO |
47
|
|
|
|
0
|
1
|
|
sub cleanup { |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# go to session dir |
50
|
|
|
|
|
|
|
# find all ado.* files |
51
|
|
|
|
|
|
|
# filter against file age where is older than session timeout |
52
|
|
|
|
|
|
|
# unlink all old files |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Warning! |
55
|
|
|
|
|
|
|
# This action will slow down the application performance, so considering |
56
|
|
|
|
|
|
|
# any other GC, like cronjob or watchdog would be a better solution. |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Ado::Sessions::File - manage sessions stored in files |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L manages sessions for |
72
|
|
|
|
|
|
|
L. All data gets serialized with L and stored |
73
|
|
|
|
|
|
|
C encoded in a file. A cookie or a request parameter can be used to |
74
|
|
|
|
|
|
|
share the session id between the server and the user agents. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L inherits all attributes from |
79
|
|
|
|
|
|
|
L and implements the following new ones. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 dstdir |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Path where to store session data files. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHODS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 absfile |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Compose absolute path to session data file. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 cleanup |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This method is a garbage collector. Cleans up expired session files. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 dstfile |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
File name of the session data file. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 load |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Load session data from file. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 store |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Store session data in file. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SEE ALSO |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L, L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|