re-usable test suite and Store::File added
[catagits/Web-Session.git] / lib / Plack / Middleware / Session.pm
CommitLineData
bd992981 1package Plack::Middleware::Session;
2use strict;
3use warnings;
4
5use Plack::Session;
6use Plack::Request;
7use Plack::Response;
fe1bfe7d 8use Plack::Session::State::Cookie;
9use Plack::Session::Store;
bd992981 10
11use parent 'Plack::Middleware';
12
13use Plack::Util::Accessor qw( state store );
14
fe1bfe7d 15sub prepare_app {
16 my $self = shift;
17 unless ($self->state) {
18 $self->state( Plack::Session::State::Cookie->new );
19 }
20
21 unless ($self->store) {
22 $self->store( Plack::Session::Store->new );
23 }
24}
25
bd992981 26sub call {
27 my $self = shift;
28 my $env = shift;
29
30 $env->{'psgix.session'} = Plack::Session->new(
3dbe8dfa 31 state => $self->state,
bd992981 32 store => $self->store,
33 request => Plack::Request->new( $env )
34 );
35
fe1bfe7d 36 my $res = $self->app->($env);
37 $self->response_cb($res, sub {
38 my $res = Plack::Response->new(@{$_[0]});
39 $env->{'psgix.session'}->finalize( $res );
40 @{$_[0]} = @{$res->finalize};
41 });
bd992981 42}
43
441;
45
46__END__
ac4892f4 47
48=pod
49
50=head1 NAME
51
52Plack::Middleware::Session - Middleware for session management
53
54=head1 SYNOPSIS
55
56 use Plack::Middleware::Session;
57
58=head1 DESCRIPTION
59
60=head1 BUGS
61
62All complex software has bugs lurking in it, and this module is no
63exception. If you find a bug please either email me, or add the bug
64to cpan-RT.
65
66=head1 AUTHOR
67
68Tatsuhiko Miyagawa
69
70Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
71
72=head1 COPYRIGHT AND LICENSE
73
74Copyright 2009 Infinity Interactive, Inc.
75
76L<http://www.iinteractive.com>
77
78This library is free software; you can redistribute it and/or modify
79it under the same terms as Perl itself.
80
81=cut
82
83