line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Session::Store::File; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23004
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw( Class::Data::Inheritable Catalyst::Plugin::Session::Store ); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
881
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use MRO::Compat; |
9
|
|
|
|
|
|
|
use Cache::FileCache (); |
10
|
|
|
|
|
|
|
use Catalyst::Utils (); |
11
|
|
|
|
|
|
|
use Path::Class (); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.18'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata(qw/_session_file_storage/); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Catalyst::Plugin::Session::Store::File - File storage backend for session data. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Catalyst qw/Session Session::Store::File Session::State::Foo/; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
MyApp->config->{'Plugin::Session'} = { |
26
|
|
|
|
|
|
|
storage => '/tmp/session' |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# ... in an action: |
30
|
|
|
|
|
|
|
$c->session->{foo} = 'bar'; # will be saved |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
C<Catalyst::Plugin::Session::Store::File> is an easy to use storage plugin |
35
|
|
|
|
|
|
|
for Catalyst that uses an simple file to act as a shared memory interprocess |
36
|
|
|
|
|
|
|
cache. It is based on C<Cache::FileCache>. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 4 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item get_session_data |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item store_session_data |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item delete_session_data |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item delete_expired_sessions |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
These are implementations of the required methods for a store. See |
51
|
|
|
|
|
|
|
L<Catalyst::Plugin::Session::Store>. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_session_data { |
56
|
|
|
|
|
|
|
my ( $c, $sid ) = @_; |
57
|
|
|
|
|
|
|
$c->_check_session_file_storage; |
58
|
|
|
|
|
|
|
$c->_session_file_storage->get($sid); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub store_session_data { |
62
|
|
|
|
|
|
|
my ( $c, $sid, $data ) = @_; |
63
|
|
|
|
|
|
|
$c->_check_session_file_storage; |
64
|
|
|
|
|
|
|
$c->_session_file_storage->set( $sid, $data ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub delete_session_data { |
68
|
|
|
|
|
|
|
my ( $c, $sid ) = @_; |
69
|
|
|
|
|
|
|
$c->_check_session_file_storage; |
70
|
|
|
|
|
|
|
$c->_session_file_storage->remove($sid); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub delete_expired_sessions { } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item setup_session |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Sets up the session cache file. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub setup_session { |
82
|
|
|
|
|
|
|
my $c = shift; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$c->maybe::next::method(@_); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _check_session_file_storage { |
88
|
|
|
|
|
|
|
my $c = shift; |
89
|
|
|
|
|
|
|
return if $c->_session_file_storage; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$c->_session_plugin_config->{namespace} ||= ''; |
92
|
|
|
|
|
|
|
my $root = $c->_session_plugin_config->{storage} ||= |
93
|
|
|
|
|
|
|
File::Spec->catdir( Catalyst::Utils::class2tempdir(ref $c), |
94
|
|
|
|
|
|
|
"session", "data", ); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$root = $c->path_to($root) if $c->_session_plugin_config->{relative}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Path::Class::dir($root)->mkpath; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $cfg = $c->_session_plugin_config; |
101
|
|
|
|
|
|
|
$c->_session_file_storage( |
102
|
|
|
|
|
|
|
Cache::FileCache->new( |
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
cache_root => $cfg->{storage}, |
105
|
|
|
|
|
|
|
( |
106
|
|
|
|
|
|
|
map { $_ => $cfg->{$_} } |
107
|
|
|
|
|
|
|
grep { exists $cfg->{$_} } |
108
|
|
|
|
|
|
|
qw/namespace cache_depth directory_umask/ |
109
|
|
|
|
|
|
|
), |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
) |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 CONFIGURATION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
These parameters are placed in the hash under the C<Plugin::Session> key in the |
120
|
|
|
|
|
|
|
configuration hash. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item storage |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Specifies the directory root to be used for the sharing of session data. The default |
127
|
|
|
|
|
|
|
value will use L<File::Spec> to find the default tempdir, and use a file named |
128
|
|
|
|
|
|
|
C<MyApp/session/data>, where C<MyApp> is replaced with the appname. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Note that the file will be created with mode 0640, which means that it |
131
|
|
|
|
|
|
|
will only be writeable by processes running with the same uid as the |
132
|
|
|
|
|
|
|
process that creates the file. If this may be a problem, for example |
133
|
|
|
|
|
|
|
if you may try to debug the program as one user and run it as another, |
134
|
|
|
|
|
|
|
specify a directory like C<< /tmp/session-$> >>, which includes the |
135
|
|
|
|
|
|
|
UID of the process in the filename. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item relative |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Makes the storage path relative to I<$c->path_to> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item namespace |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The namespace associated with this cache. Defaults to an empty string if not explicitly set. |
144
|
|
|
|
|
|
|
If set, the session data will be stored in a directory called C<MyApp/session/data/<namespace>>. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item cache_depth |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The number of subdirectories deep to session object item. This should be large enough that |
149
|
|
|
|
|
|
|
no session directory has more than a few hundred objects. Defaults to 3 unless explicitly set. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item directory_umask |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The directories in the session on the filesystem should be globally writable to allow for |
154
|
|
|
|
|
|
|
multiple users. While this is a potential security concern, the actual cache entries are |
155
|
|
|
|
|
|
|
written with the user's umask, thus reducing the risk of cache poisoning. If you desire it |
156
|
|
|
|
|
|
|
to only be user writable, set the 'directory_umask' option to '077' or similar. Defaults |
157
|
|
|
|
|
|
|
to '000' unless explicitly set. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Plugin::Session>, L<Cache::FileCache>. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Sascha Kiefer, L<esskar@cpan.org> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright (C) 2005 Sascha Kiefer |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
174
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |