| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::WWWSession; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22524
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
68
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Mojolicious::Plugin::WWWSession - Use WWWW::Session with Mojolicious |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head2 DESCRIPTION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
An alternative session implementation for Mojolicious based on WWW::Session |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.05 |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module allows you to overwrite the standard Mojolicious session with a WWW::Session object and enjoy all the goodies it provides |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Example : |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Storage backends |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
You can use one or more of the fallowing backends : |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head3 File storage |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
In you apllication module add the fallowing lines |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Mojolicious::Plugin::WWWSession; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub startup { |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
... |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#Overwrite session |
|
44
|
|
|
|
|
|
|
$self->plugin( WWWSession => { storage => [File => {path => '.'}] } ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
... |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
See WWW::Session::Storage::File for more details |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head3 Database storage |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
In you apllication module add the fallowing lines |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Mojolicious::Plugin::WWWSession; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub startup { |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
... |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#Overwrite session |
|
62
|
|
|
|
|
|
|
$self->plugin( WWWSession => { storage => [ MySQL => { |
|
63
|
|
|
|
|
|
|
dbh => $dbh, |
|
64
|
|
|
|
|
|
|
table => 'sessions', |
|
65
|
|
|
|
|
|
|
fields => { |
|
66
|
|
|
|
|
|
|
sid => 'session_id', |
|
67
|
|
|
|
|
|
|
expires => 'expires', |
|
68
|
|
|
|
|
|
|
data => 'data' |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
] |
|
71
|
|
|
|
|
|
|
} ); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
... |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The "fields" hasref contains the mapping of session internal data to the column names from MySQL. |
|
77
|
|
|
|
|
|
|
The keys are the session fields ("sid","expires" and "data") and must all be present. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The MySQL types of the columns should be : |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over 4 |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item * sid => varchar(32) |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * expires => DATETIME or TIMESTAMP |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * data => text |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
See WWW::Session::Storage::MySQL for more details |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 Memcached storage |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
In you apllication module add the fallowing lines |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Mojolicious::Plugin::WWWSession; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub startup { |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
... |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#Overwrite session |
|
104
|
|
|
|
|
|
|
$self->plugin( WWWSession => { storage => ['Memcached' => {servers => ['127.0.0.1:11211']}] } ); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
... |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
See WWW::Session::Storage::Memcached for more details |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 Using the session |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This session can be used in the exact same way the strandard Mojolicious session is used |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 Possible options for the plugin |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Here is an exmple containing the options you can pass to the plugin: |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
{ |
|
121
|
|
|
|
|
|
|
storage => [ 'File' => { path => '/tmp/sessions'}, |
|
122
|
|
|
|
|
|
|
'Memcached' => { servers => ['127.0.0.1'] } |
|
123
|
|
|
|
|
|
|
], |
|
124
|
|
|
|
|
|
|
serialization => 'JSON', |
|
125
|
|
|
|
|
|
|
expires => 3600, |
|
126
|
|
|
|
|
|
|
fields => { |
|
127
|
|
|
|
|
|
|
user => { |
|
128
|
|
|
|
|
|
|
inflate => sub { return Some::Package->new( $_[0] ) }, |
|
129
|
|
|
|
|
|
|
deflate => sub { $_[0]->id() }, |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
age => { |
|
132
|
|
|
|
|
|
|
filter => [21..99], |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
See WWW:Session for more details on possible options and on how you can use the session |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
If you use the "Storable" serialization engine you can store objects in the session. |
|
139
|
|
|
|
|
|
|
Also multiple session storage backends can be used simultaneously |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
1
|
|
|
1
|
|
6
|
use base 'Mojolicious::Plugin'; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
854
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
1
|
|
|
1
|
|
13303
|
use WWW::Session; |
|
|
1
|
|
|
|
|
23681
|
|
|
|
1
|
|
|
|
|
7
|
|
|
146
|
1
|
|
|
1
|
|
79
|
use Digest::MD5 qw(md5_hex); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
227
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 METHODS |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 register |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Called by Mojo when you register the plugin |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub register { |
|
157
|
0
|
|
|
0
|
1
|
|
my ($self, $app, $args) = @_; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
0
|
|
|
|
$args ||= {}; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
WWW::Session->import(%$args); |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$app->hook( |
|
164
|
|
|
|
|
|
|
before_dispatch => sub { |
|
165
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
0
|
|
|
|
my $sid = $self->cookie('sid') || md5_hex($$ + time() + rand(time())); |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$self->cookie(sid => $sid); |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
my %session; |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
tie %session, 'WWW::Session' , $sid, {sid => $sid}, $args->{expires}; |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
$self->stash('mojo.session' => \%session); |
|
176
|
|
|
|
|
|
|
} |
|
177
|
0
|
|
|
|
|
|
); |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 AUTHOR |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Gligan Calin Horea, C<< >> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Also thanks to Florian Adamsky for contributting with patches. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 BUGS |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
191
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
192
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 SUPPORT |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
perldoc Mojolicious::Plugin::WWWSession |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
You can also look for information at: |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=over 4 |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
L |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * Search CPAN |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Copyright 2012 Gligan Calin Horea. |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
233
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
234
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; # End of Mojolicious::Plugin::WWWSession |