line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Session::Storage::File; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
1503
|
use 5.006; |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
176
|
|
4
|
5
|
|
|
5
|
|
19
|
use strict; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
127
|
|
5
|
5
|
|
|
5
|
|
16
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
1726
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
WWW::Session::Storage::File - File storage engine for WWW::Session |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
File backend for WWWW::Session |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.12 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module is used for storring serialized WWW::Session objects |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Usage : |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use WWW::Session::Storage::File; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $storage = WWW::Session::Storage::File->new({path => '/tmp/sessions'}); |
33
|
|
|
|
|
|
|
... |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$storage->save($session_id,$expires,$serialized_data); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $serialized_data = $storage->retrive($session_id); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Creates a new WWW::Session::Storage::File object |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This method accepts only one argument, a hashref that must contain a key named |
47
|
|
|
|
|
|
|
"path" which defines the path where the sessions will be saved |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
4
|
|
|
4
|
1
|
779
|
my ($class,$params) = @_; |
53
|
|
|
|
|
|
|
|
54
|
4
|
50
|
|
|
|
916
|
die "You must specify the path where to save the sessions!" unless defined $params->{path}; |
55
|
|
|
|
|
|
|
|
56
|
4
|
50
|
|
|
|
61
|
die "Cannot save sessions in folder '".$params->{path}."' because the folder does not exist!" unless -d $params->{path}; |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
13
|
my $self = { |
59
|
|
|
|
|
|
|
path => $params->{path} |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
15
|
bless $self, $class; |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
14
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 save |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Stores the given information into the file |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
sub save { |
73
|
23
|
|
|
23
|
1
|
1893
|
my ($self,$sid,$expires,$string) = @_; |
74
|
|
|
|
|
|
|
|
75
|
23
|
|
|
|
|
2154
|
open(my $fh,">",$self->{path}."/".$sid); |
76
|
|
|
|
|
|
|
|
77
|
23
|
|
|
|
|
197
|
print $fh $expires . "\n"; |
78
|
23
|
|
|
|
|
55
|
print $fh $string; |
79
|
|
|
|
|
|
|
|
80
|
23
|
|
|
|
|
1189
|
close($fh); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 retrieve |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Retrieves the informations for a session, verifies that it's not expired and returns |
86
|
|
|
|
|
|
|
the string containing the serialized data |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
sub retrieve { |
90
|
12
|
|
|
12
|
1
|
26
|
my ($self,$sid) = @_; |
91
|
|
|
|
|
|
|
|
92
|
12
|
|
|
|
|
47
|
my $filename = $self->{path}."/".$sid; |
93
|
|
|
|
|
|
|
|
94
|
12
|
100
|
|
|
|
194
|
return undef unless -f $filename; |
95
|
|
|
|
|
|
|
|
96
|
9
|
|
|
|
|
91
|
my @file_info = stat($filename); |
97
|
|
|
|
|
|
|
|
98
|
9
|
50
|
|
|
|
261
|
open(my $fh,"<",$self->{path}."/".$sid) || return undef; |
99
|
|
|
|
|
|
|
|
100
|
9
|
|
|
|
|
46
|
local $/ = "\n"; |
101
|
|
|
|
|
|
|
|
102
|
9
|
|
|
|
|
88
|
my $expires= readline($fh); |
103
|
|
|
|
|
|
|
|
104
|
9
|
|
|
|
|
24
|
local $/ = undef; |
105
|
|
|
|
|
|
|
|
106
|
9
|
|
|
|
|
59
|
my $string = readline($fh); |
107
|
|
|
|
|
|
|
|
108
|
9
|
|
|
|
|
72
|
close($fh); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#check if it didn't expire |
111
|
9
|
100
|
100
|
|
|
64
|
if ($expires != -1 && ($file_info[8] + $expires) < time() ) { |
112
|
1
|
|
|
|
|
120
|
unlink $filename; |
113
|
1
|
|
|
|
|
17
|
return undef; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
8
|
|
|
|
|
62
|
return $string; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 delete |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Completely removes the session data for the given session id |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
sub delete { |
125
|
20
|
|
|
20
|
1
|
3242
|
my ($self,$sid) = @_; |
126
|
|
|
|
|
|
|
|
127
|
20
|
|
|
|
|
53
|
my $filename = $self->{path}."/".$sid; |
128
|
|
|
|
|
|
|
|
129
|
20
|
50
|
|
|
|
312
|
if (-f $filename) { |
130
|
20
|
|
|
|
|
1495
|
unlink($filename); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Gligan Calin Horea, C<< >> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 BUGS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
141
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
142
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SUPPORT |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
perldoc WWW::Session::Storage::File |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
You can also look for information at: |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * CPAN Ratings |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * Search CPAN |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Copyright 2012 Gligan Calin Horea. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
185
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
186
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; # End of WWW::Session::Storage::File |