| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Session::FastMmap; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26664
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use base qw/Class::Accessor::Fast Class::Data::Inheritable/; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
865
|
|
|
5
|
1
|
|
|
1
|
|
36103
|
use MRO::Compat; |
|
|
1
|
|
|
|
|
3002
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
1194
|
use Cache::FastMmap; |
|
|
1
|
|
|
|
|
10153
|
|
|
|
1
|
|
|
|
|
65
|
|
|
7
|
1
|
|
|
1
|
|
12
|
use Digest::MD5; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
49
|
|
|
8
|
1
|
|
|
1
|
|
1041
|
use URI; |
|
|
1
|
|
|
|
|
9966
|
|
|
|
1
|
|
|
|
|
33
|
|
|
9
|
1
|
|
|
1
|
|
1201
|
use URI::Find; |
|
|
1
|
|
|
|
|
2836
|
|
|
|
1
|
|
|
|
|
71
|
|
|
10
|
1
|
|
|
1
|
|
1473
|
use File::Temp 'tempdir'; |
|
|
1
|
|
|
|
|
25133
|
|
|
|
1
|
|
|
|
|
884
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata('_session'); |
|
15
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('sessionid'); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Catalyst::Plugin::Session::FastMmap - [DEPRECATED] FastMmap sessions for Catalyst |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DEPRECATION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Note that this module is deprecated in favor of L<Catalyst::Plugin::Session>. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
It works under Catalyst 5.5, but might not work in future versions. Using |
|
26
|
|
|
|
|
|
|
L<Catalyst::Plugin::Session> should be a small change, since the API is mostly |
|
27
|
|
|
|
|
|
|
backwards compatible. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Catalyst 'Session::FastMmap'; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
MyApp->config->{session} = { |
|
34
|
|
|
|
|
|
|
expires => 3600, |
|
35
|
|
|
|
|
|
|
rewrite => 1, |
|
36
|
|
|
|
|
|
|
storage => '/tmp/session' |
|
37
|
|
|
|
|
|
|
}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$c->session->{foo} = 'bar'; |
|
40
|
|
|
|
|
|
|
print $c->sessionid; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
C<Catalyst::Plugin::Session::FastMmap> is a fast session plugin for |
|
45
|
|
|
|
|
|
|
Catalyst that uses an mmap'ed file to act as a shared memory |
|
46
|
|
|
|
|
|
|
interprocess cache. It is based on C<Cache::FastMMap>. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 EXTENDED METHODS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over 4 |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item finalize |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub finalize { |
|
58
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
59
|
0
|
0
|
|
|
|
|
if ( $c->config->{session}->{rewrite} ) { |
|
60
|
0
|
|
|
|
|
|
my $redirect = $c->response->redirect; |
|
61
|
0
|
0
|
|
|
|
|
$c->response->redirect( $c->uri($redirect) ) if $redirect; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
0
|
|
|
|
|
if ( my $sid = $c->sessionid ) { |
|
64
|
0
|
|
|
|
|
|
$c->_session->set( $sid, $c->session ); |
|
65
|
0
|
|
|
|
|
|
my $set = 1; |
|
66
|
0
|
0
|
|
|
|
|
if ( my $cookie = $c->request->cookies->{session} ) { |
|
67
|
0
|
0
|
|
|
|
|
$set = 0 if $cookie->value eq $sid; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
0
|
|
|
|
|
if ( $set ) { |
|
70
|
0
|
|
|
|
|
|
$c->response->cookies->{session} = { |
|
71
|
|
|
|
|
|
|
value => $sid |
|
72
|
|
|
|
|
|
|
}; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
0
|
|
|
|
|
if ( $c->config->{session}->{rewrite} ) { |
|
75
|
|
|
|
|
|
|
my $finder = URI::Find->new( |
|
76
|
|
|
|
|
|
|
sub { |
|
77
|
0
|
|
|
0
|
|
|
my ( $uri, $orig ) = @_; |
|
78
|
0
|
|
|
|
|
|
my $base = $c->request->base; |
|
79
|
0
|
0
|
|
|
|
|
return $orig unless $orig =~ /^$base/; |
|
80
|
0
|
0
|
|
|
|
|
return $orig if $uri->path =~ /\/-\//; |
|
81
|
0
|
|
|
|
|
|
return $c->uri($orig); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
); |
|
84
|
0
|
0
|
|
|
|
|
$finder->find( \$c->res->{body} ) if $c->res->body; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} |
|
87
|
0
|
|
|
|
|
|
return $c->NEXT::finalize(@_); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item prepare_action |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub prepare_action { |
|
95
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
96
|
0
|
0
|
|
|
|
|
if ( $c->request->path =~ /^(.*)\/\-\/(.+)$/ ) { |
|
97
|
0
|
|
|
|
|
|
$c->request->path($1); |
|
98
|
0
|
|
|
|
|
|
$c->sessionid($2); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
0
|
|
|
|
|
if ( my $cookie = $c->request->cookies->{session} ) { |
|
101
|
0
|
|
|
|
|
|
my $sid = $cookie->value; |
|
102
|
0
|
|
|
|
|
|
$c->sessionid($sid); |
|
103
|
0
|
0
|
|
|
|
|
$c->log->debug(qq/Found sessionid "$sid" in cookie/) if $c->debug; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
|
|
|
|
|
$c->NEXT::prepare_action(@_); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub session { |
|
109
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
110
|
0
|
0
|
|
|
|
|
return $c->{session} if $c->{session}; |
|
111
|
0
|
|
|
|
|
|
my $sid = $c->sessionid; |
|
112
|
0
|
0
|
0
|
|
|
|
if ( $sid |
|
|
|
|
0
|
|
|
|
|
|
113
|
|
|
|
|
|
|
&& $c->_session |
|
114
|
|
|
|
|
|
|
&& ( $c->{session} = $c->_session->get($sid) ) ) |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
0
|
0
|
|
|
|
|
$c->log->debug(qq/Found session "$sid"/) if $c->debug; |
|
117
|
0
|
|
|
|
|
|
return $c->{session}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
else { |
|
120
|
0
|
|
|
|
|
|
my $sid = Digest::MD5::md5_hex( time, rand, $$, 'catalyst' ); |
|
121
|
0
|
|
|
|
|
|
$c->sessionid($sid); |
|
122
|
0
|
0
|
|
|
|
|
$c->log->debug(qq/Created session "$sid"/) if $c->debug; |
|
123
|
0
|
|
|
|
|
|
return $c->{session} = {}; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item setup |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Sets up the session cache file. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub setup { |
|
134
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
135
|
0
|
|
0
|
|
|
|
$self->config->{session}->{storage} ||= '/tmp/session'; |
|
136
|
0
|
|
0
|
|
|
|
$self->config->{session}->{expires} ||= 60 * 60 * 24; |
|
137
|
0
|
|
0
|
|
|
|
$self->config->{session}->{rewrite} ||= 0; |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$self->_session( |
|
140
|
|
|
|
|
|
|
Cache::FastMmap->new( |
|
141
|
|
|
|
|
|
|
share_file => $self->config->{session}->{storage}, |
|
142
|
|
|
|
|
|
|
expire_time => $self->config->{session}->{expires} |
|
143
|
|
|
|
|
|
|
) |
|
144
|
|
|
|
|
|
|
); |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return $self->NEXT::setup(@_); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 METHODS |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over 4 |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item session |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item uri |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Extends an uri with session id if needed. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $uri = $c->uri('http://localhost/foo'); |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub uri { |
|
166
|
0
|
|
|
0
|
1
|
|
my ( $c, $uri ) = @_; |
|
167
|
0
|
0
|
|
|
|
|
if ( my $sid = $c->sessionid ) { |
|
168
|
0
|
|
|
|
|
|
$uri = URI->new($uri); |
|
169
|
0
|
|
|
|
|
|
my $path = $uri->path; |
|
170
|
0
|
0
|
|
|
|
|
$path .= '/' unless $path =~ /\/$/; |
|
171
|
0
|
|
|
|
|
|
$uri->path( $path . "-/$sid" ); |
|
172
|
0
|
|
|
|
|
|
return $uri->as_string; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
0
|
|
|
|
|
|
return $uri; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 CONFIG OPTIONS |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item rewrite |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
If set to a true value sessions are automatically stored in the url; |
|
186
|
|
|
|
|
|
|
defaults to false. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item storage |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Specifies the file to be used for the sharing of session data; |
|
191
|
|
|
|
|
|
|
defaults to C</tmp/session>. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Note that the file will be created with mode 0640, which means that it |
|
194
|
|
|
|
|
|
|
will only be writeable by processes running with the same uid as the |
|
195
|
|
|
|
|
|
|
process that creates the file. If this may be a problem, for example |
|
196
|
|
|
|
|
|
|
if you may try to debug the program as one user and run it as another, |
|
197
|
|
|
|
|
|
|
specify a filename like C<< /tmp/session-$> >>, which includes the |
|
198
|
|
|
|
|
|
|
UID of the process in the filename. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item expires |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Specifies the session expiry time in seconds; defaults to 86,400, |
|
204
|
|
|
|
|
|
|
i.e. one day. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=back |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L<Catalyst>, L<Cache::FastMmap>, L<Catalyst::Plugin::Session>. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Sebastian Riedel E<lt>C<sri@cpan.org>E<gt>, |
|
215
|
|
|
|
|
|
|
Marcus Ramberg E<lt>C<mramberg@cpan.org>E<gt>, |
|
216
|
|
|
|
|
|
|
Andrew Ford E<lt>C<andrewf@cpan.org>E<gt> |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it |
|
221
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; |