File Coverage

lib/Catalyst/Plugin/Session/PSGI.pm
Criterion Covered Total %
statement 6 8 75.0
branch 0 2 0.0
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 13 61.5


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::Session::PSGI;
2             {
3             $Catalyst::Plugin::Session::PSGI::VERSION = '0.0.2';
4             }
5             {
6             $Catalyst::Plugin::Session::PSGI::DIST = 'Catalyst-Plugin-Session-PSGI';
7             }
8 1     1   91 use strict;
  1         2  
  1         33  
9 1     1   5 use warnings;
  1         2  
  1         114  
10              
11              
12             sub _psgi_env {
13 0     0     my ( $c ) = @_;
14              
15 0 0         return $c->request->can('env') ? $c->request->env : $c->request->{_psgi_env};
16             }
17              
18              
19              
20              
21              
22              
23              
24             1;
25             # ABSTRACT: minimal configuration access to PSGI/Plack session (EXPERIMENTAL)
26              
27             =pod
28              
29             =head1 NAME
30              
31             Catalyst::Plugin::Session::PSGI - minimal configuration access to PSGI/Plack session (EXPERIMENTAL)
32              
33             =head1 VERSION
34              
35             version 0.0.2
36              
37             =head1 SYNOPSIS
38              
39             When running under PSG/Plack with Session middeware enabled you can use the
40             PSGI session as follows:
41              
42             use Catalyst qw/
43             Session
44             Session::State::PSGI
45             Session::Store::PSGI
46             /;
47              
48             =head2 _psgi_env
49              
50             Fetches the psgi env globally from the request env
51              
52             =head1 EXPERIMENTAL
53              
54             This distribution should be considered B<experimental>. Although functional, it
55             may break in currently undiscovered use cases.
56              
57             =head1 SUMMARY
58              
59             If you are running your L<Catalyst> application in a Plack/PSGI environment and
60             using L<Plack::Middleware::Session> you might want to consider using the
61             session information in the PSGI environment.
62              
63             The L<Catalyst::Plugin::Session::State::PSGI> and
64             L<Catalyst::Plugin::Session::Store::PSGI> modules access the
65             I<psgix.session.options> and I<psgix.session> data to provide the Catalyst
66             session.
67              
68             =head1 AREAS OF CONCERN
69              
70             As this is an early, experimental release I thought it only fair to share the
71             glaring areas of concern:
72              
73             =over 4
74              
75             =item session expiry
76              
77             I currently believe that it should be the responsibility of the L<Plack>
78             middleware to expire and clear session data. As far as possible this
79             functionality is unimplemented and unsupported in this distribution.
80              
81             =item session expiry value initialisation
82              
83             There was a problem with the session expiry value being unset in the Catalyst
84             related code. This led to sessions always being deleted/expired and never
85             working properly.
86              
87             There are a couple of dubious areas to resolve this.
88              
89             sub get_session_data {
90             # ...
91              
92             # TODO: work out correct place to initialise this
93             $psgi_env->{'psgix.session.expires'}
94             ||= $c->get_session_expires;
95              
96             # ...
97             }
98              
99             is almost certainly the wrong time and place to be initialising this value, but
100             it works and I'm open to clue-sticks and patches.
101              
102             sub get_session_expires {
103             my $c = shift;
104             my $expires = $c->_session_plugin_config->{expires} || 0;
105             return time() + $expires;
106             }
107              
108             worries me because I have no idea where the value for
109             C<< $c->_session_plugin_config->{expires} >> is being initialised. I'm concerned
110             that this may become C<0> when you least expect it and start expiring all
111             sessions.
112              
113             =item (lack of) test coverage
114              
115             Other than basic sanity tests provided by L<Dist::Zilla> this distribution B<has no tests>!
116              
117             I haven't found the time to mock up a plack-catalyst test suite to ensure the
118             session is doing the right thing. Once again I'm open to clue-sticks and
119             patches.
120              
121             =back
122              
123             =head1 SEE ALSO
124              
125             L<Catalyst>,
126             L<Catalyst::Plugin::Session>,
127             L<Plack::Middleware::Session>,
128             L<Catalyst::Plugin::Session::State::PSGI>,
129             L<Catalyst::Plugin::Session::Store::PSGI>
130              
131             =head1 AUTHOR
132              
133             Chisel <chisel@chizography.net>
134              
135             =head1 COPYRIGHT AND LICENSE
136              
137             This software is copyright (c) 2011 by Chisel Wright.
138              
139             This is free software; you can redistribute it and/or modify it under
140             the same terms as the Perl 5 programming language system itself.
141              
142             =cut
143              
144             __END__
145             # vim: ts=8 sts=4 et sw=4 sr sta