line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Engine::Middleware::HTTPSession; |
2
|
1
|
|
|
1
|
|
467
|
use HTTP::Engine::Middleware; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw/blessed/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
4
|
use Any::Moose 'X::Types' => [ -declare => [qw/State Store/] ]; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
240
|
use HTTP::Session; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
subtype State, |
8
|
|
|
|
|
|
|
as 'CodeRef'; |
9
|
|
|
|
|
|
|
coerce State, |
10
|
|
|
|
|
|
|
from 'Object', |
11
|
|
|
|
|
|
|
via { |
12
|
|
|
|
|
|
|
my $x = $_; |
13
|
|
|
|
|
|
|
sub { $x } |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
coerce State, |
16
|
|
|
|
|
|
|
from 'HashRef', |
17
|
|
|
|
|
|
|
via { |
18
|
|
|
|
|
|
|
my $klass = $_->{class}; |
19
|
|
|
|
|
|
|
$klass = $klass =~ s/^\+// ? $klass : "HTTP::Session::State::${klass}"; |
20
|
|
|
|
|
|
|
Any::Moose::load_class($klass); |
21
|
|
|
|
|
|
|
my $obj = $klass->new( $_->{args} ); |
22
|
|
|
|
|
|
|
sub { $obj }; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
subtype Store, |
26
|
|
|
|
|
|
|
as 'CodeRef'; |
27
|
|
|
|
|
|
|
coerce Store, |
28
|
|
|
|
|
|
|
from 'Object', |
29
|
|
|
|
|
|
|
via { |
30
|
|
|
|
|
|
|
my $x = $_; |
31
|
|
|
|
|
|
|
sub { $x } |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
coerce Store, |
34
|
|
|
|
|
|
|
from 'HashRef', |
35
|
|
|
|
|
|
|
via { |
36
|
|
|
|
|
|
|
my $klass = $_->{class}; |
37
|
|
|
|
|
|
|
$klass = $klass =~ s/^\+// ? $klass : "HTTP::Session::Store::${klass}"; |
38
|
|
|
|
|
|
|
Any::Moose::load_class($klass); |
39
|
|
|
|
|
|
|
my $obj = $klass->new( $_->{args} ); |
40
|
|
|
|
|
|
|
sub { $obj }; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'state' => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
isa => State, |
46
|
|
|
|
|
|
|
coerce => 1, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'store' => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => Store, |
52
|
|
|
|
|
|
|
coerce => 1, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
my $SESSION; |
57
|
|
|
|
|
|
|
my $SELF; |
58
|
|
|
|
|
|
|
my $REQ; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
middleware_method 'session' => sub { |
61
|
1
|
|
33
|
1
|
|
13
|
$SESSION ||= HTTP::Session->new( |
62
|
|
|
|
|
|
|
state => $SELF->state->(), |
63
|
|
|
|
|
|
|
store => $SELF->store->(), |
64
|
|
|
|
|
|
|
request => $REQ, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
before_handle { |
69
|
|
|
|
|
|
|
(undef, $SELF, $REQ) = @_; |
70
|
|
|
|
|
|
|
undef $SESSION; |
71
|
|
|
|
|
|
|
$REQ; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
after_handle { |
75
|
|
|
|
|
|
|
my ($c, $self, $req, $res) = @_; |
76
|
|
|
|
|
|
|
if ($SESSION) { |
77
|
|
|
|
|
|
|
$SESSION->response_filter($res); |
78
|
|
|
|
|
|
|
$SESSION->finalize(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
undef $SESSION; |
81
|
|
|
|
|
|
|
undef $SELF; |
82
|
|
|
|
|
|
|
undef $REQ; |
83
|
|
|
|
|
|
|
$res; |
84
|
|
|
|
|
|
|
}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__MIDDLEWARE__ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
HTTP::Engine::Middleware::HTTPSession - session support at middleware layer |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $mw = HTTP::Engine::Middleware->new; |
98
|
|
|
|
|
|
|
$mw->install( 'HTTP::Engine::Middleware::HTTPSession' => { |
99
|
|
|
|
|
|
|
state => { |
100
|
|
|
|
|
|
|
class => 'URI', |
101
|
|
|
|
|
|
|
args => { |
102
|
|
|
|
|
|
|
session_id_name => 'foo_sid', |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
}, |
105
|
|
|
|
|
|
|
store => { |
106
|
|
|
|
|
|
|
class => 'Test', |
107
|
|
|
|
|
|
|
args => { }, |
108
|
|
|
|
|
|
|
}, |
109
|
|
|
|
|
|
|
}); |
110
|
|
|
|
|
|
|
HTTP::Engine->new( |
111
|
|
|
|
|
|
|
interface => { |
112
|
|
|
|
|
|
|
module => 'YourFavoriteInterfaceHere', |
113
|
|
|
|
|
|
|
request_handler => $mw->handler( \&handler ), |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
)->run(); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DESCRIPTION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This middleware add the session management stuff for your web application |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
tokuhirom |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L<HTTP::Engine::Middleware>, L<HTTP::Session> |
128
|
|
|
|
|
|
|
|