line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eve::Session; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25724
|
use parent qw(Eve::Class); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
55
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
40
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6801
|
use CGI::Session; |
|
1
|
|
|
|
|
15897
|
|
|
1
|
|
|
|
|
10
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
B - a persistent session class. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Construct the session object |
17
|
|
|
|
|
|
|
my $session = Eve::Session->new( |
18
|
|
|
|
|
|
|
id => $md5_id, |
19
|
|
|
|
|
|
|
storage_path => '/storage/path', |
20
|
|
|
|
|
|
|
expiration_interval => 3600); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Get the session identifier |
23
|
|
|
|
|
|
|
my $id = $session->get_id(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Set ang get the parameter |
26
|
|
|
|
|
|
|
$session->set_parameter(name => 'foo', value => 'bar'); |
27
|
|
|
|
|
|
|
my $foo = $session->get_parameter(name => 'foo'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Set the parameter expired after 600 seconds of idling |
30
|
|
|
|
|
|
|
$session->set_parameter( |
31
|
|
|
|
|
|
|
name => 'foo', value => 'bar', expiration_interval => 600); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Clear the parameter |
34
|
|
|
|
|
|
|
$session->clear_parameter(name => 'foo'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
B is a persistent session class allowing to share an |
39
|
|
|
|
|
|
|
identified state between application calls. The class adapts the |
40
|
|
|
|
|
|
|
package B. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head3 Constructor arguments |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over 4 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item C |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
a session ID string (it can differ from the actual ID, see the |
49
|
|
|
|
|
|
|
C method documentation) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item C |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
a path on the server where session files are stored |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item C |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
an interval of idling from the last access when the session is |
58
|
|
|
|
|
|
|
considered actual (0 cancels expiration). |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=back |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head3 Attributes |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item C |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
(read only) an expiration interval in seconds that has been initially |
69
|
|
|
|
|
|
|
set for the session. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=back |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head3 Throws |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item C |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
when the session creation is unsuccessful. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 B |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub init { |
90
|
16
|
|
|
16
|
1
|
145
|
my ($self, %arg_hash) = @_; |
91
|
16
|
|
|
|
|
81
|
Eve::Support::arguments( |
92
|
|
|
|
|
|
|
\%arg_hash, |
93
|
|
|
|
|
|
|
my ($id, $storage_path, $expiration_interval)); |
94
|
|
|
|
|
|
|
|
95
|
16
|
|
|
|
|
399
|
$self->{'session'} = CGI::Session->new( |
96
|
|
|
|
|
|
|
undef, $id, { Directory => $storage_path }); |
97
|
|
|
|
|
|
|
|
98
|
16
|
100
|
|
|
|
393294
|
if (not defined $self->session) { |
99
|
4
|
|
|
|
|
41
|
Eve::Error::Session->throw(message => CGI::Session->errstr()); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
12
|
|
|
|
|
216
|
$self->session->expire($expiration_interval); |
103
|
|
|
|
|
|
|
|
104
|
12
|
|
|
|
|
580
|
$self->{'expiration_interval'} = $self->session->expire(); |
105
|
|
|
|
|
|
|
|
106
|
12
|
|
|
|
|
349
|
$self->_flush(); |
107
|
|
|
|
|
|
|
|
108
|
12
|
|
|
|
|
4009161
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 B |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head3 Returns |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
An md5 string identified the session. The string can be different from |
116
|
|
|
|
|
|
|
one that is specified in the constructor in case of not existing or |
117
|
|
|
|
|
|
|
expired session. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub get_id { |
122
|
2
|
|
|
2
|
1
|
540
|
my $self = shift; |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
24
|
return $self->session->id(); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 B |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Sets a named parameter in the session. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head3 Arguments |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item C |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item C |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item C |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
an interval of idling from the last access when the parameter is |
142
|
|
|
|
|
|
|
considered actual (0 cancels expiration). |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head3 Returns |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The value passed to the method. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub set_parameter { |
153
|
7
|
|
|
7
|
1
|
1003921
|
my ($self, %arg_hash) = @_; |
154
|
7
|
|
|
|
|
48
|
Eve::Support::arguments( |
155
|
|
|
|
|
|
|
\%arg_hash, my ($name, $value), my $expiration_interval = \undef); |
156
|
|
|
|
|
|
|
|
157
|
7
|
|
|
|
|
127
|
my $result = $self->session->param(-name => $name, -value => $value); |
158
|
|
|
|
|
|
|
|
159
|
7
|
100
|
|
|
|
308
|
if (defined $expiration_interval) { |
160
|
3
|
|
|
|
|
16
|
$self->session->expire($name, $expiration_interval); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
7
|
|
|
|
|
121
|
$self->_flush(); |
164
|
|
|
|
|
|
|
|
165
|
7
|
|
|
|
|
21735
|
return $result; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 B |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head3 Arguments |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=over 4 |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item C |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head3 Returns |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
A parameter value. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub get_parameter { |
185
|
4
|
|
|
4
|
1
|
1001066
|
my ($self, %arg_hash) = @_; |
186
|
4
|
|
|
|
|
32
|
Eve::Support::arguments(\%arg_hash, my $name); |
187
|
|
|
|
|
|
|
|
188
|
4
|
|
|
|
|
85
|
return $self->session->param($name); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 B |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Clears the parameter from the session. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head3 Arguments |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over 4 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item C |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head3 Returns |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
An old parameter value. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub clear_parameter { |
210
|
2
|
|
|
2
|
1
|
1002744
|
my ($self, %arg_hash) = @_; |
211
|
2
|
|
|
|
|
35
|
Eve::Support::arguments(\%arg_hash, my $name); |
212
|
|
|
|
|
|
|
|
213
|
2
|
|
|
|
|
41
|
my $result = $self->session->param($name); |
214
|
2
|
|
|
|
|
66
|
$self->session->clear($name); |
215
|
|
|
|
|
|
|
|
216
|
2
|
|
|
|
|
74
|
$self->_flush(); |
217
|
|
|
|
|
|
|
|
218
|
2
|
|
|
|
|
531643
|
return $result; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _flush { |
222
|
21
|
|
|
21
|
|
41
|
my $self = shift; |
223
|
|
|
|
|
|
|
|
224
|
21
|
50
|
|
|
|
116
|
if (not $self->session->flush()) { |
225
|
0
|
|
|
|
|
|
Eve::Error::Session->throw(message => CGI::Session->errstr()); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 SEE ALSO |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=over 4 |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item L |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=back |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Copyright 2012 Igor Zinovyev. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
242
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
243
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 AUTHOR |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
L |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=cut |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1; |