Commit | Line | Data |
06190e8b |
1 | package Plack::Session::Store; |
2 | use strict; |
3 | use warnings; |
4 | |
5 | use Plack::Util::Accessor qw[ _stash ]; |
6 | |
ac4892f4 |
7 | sub new { |
8 | my ($class, %params) = @_; |
9 | $params{'_stash'} ||= +{}; |
10 | bless { %params } => $class; |
11 | } |
06190e8b |
12 | |
13 | sub fetch { |
14 | my ($self, $session_id, $key) = @_; |
15 | $self->_stash->{ $session_id }->{ $key } |
16 | } |
17 | |
18 | sub store { |
19 | my ($self, $session_id, $key, $data) = @_; |
20 | $self->_stash->{ $session_id }->{ $key } = $data; |
21 | } |
22 | |
23 | sub delete { |
24 | my ($self, $session_id, $key) = @_; |
25 | delete $self->_stash->{ $session_id }->{ $key }; |
26 | } |
27 | |
06190e8b |
28 | sub cleanup { |
29 | my ($self, $session_id) = @_; |
30 | delete $self->_stash->{ $session_id } |
31 | } |
32 | |
ac4892f4 |
33 | sub persist { |
34 | my ($self, $session_id, $response) = @_; |
35 | () |
36 | } |
37 | |
38 | 1; |
39 | |
40 | __END__ |
41 | |
42 | =pod |
43 | |
44 | =head1 NAME |
45 | |
46 | Plack::Session::Store - Basic in-memory session store |
47 | |
3d92cf47 |
48 | =head1 SYNOPSIS |
49 | |
50 | use Plack::Builder; |
51 | use Plack::Middleware::Session; |
52 | use Plack::Session::Store; |
53 | |
54 | my $app = sub { |
55 | return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ]; |
56 | }; |
57 | |
58 | builder { |
59 | enable 'Session'; # this is the defalt store |
60 | $app; |
61 | }; |
62 | |
ac4892f4 |
63 | =head1 DESCRIPTION |
64 | |
3d92cf47 |
65 | This is a very basic in-memory session data store. It is volatile |
66 | storage and not recommended for multiprocessing environments. However |
67 | it is very useful for development and testing. |
68 | |
69 | This should be considered the store "base" class (although |
70 | subclassing is not a requirement) and defines the spec for |
71 | all B<Plack::Session::Store::*> modules. You will only |
72 | need to override a couple methods if you do subclass. See |
73 | the other B<Plack::Session::Store::*> for examples of this. |
74 | |
ac4892f4 |
75 | =head1 METHODS |
76 | |
77 | =over 4 |
78 | |
79 | =item B<new ( %params )> |
80 | |
3d92cf47 |
81 | No parameters are expected to this constructor. |
82 | |
ac4892f4 |
83 | =back |
84 | |
43f34c01 |
85 | =head2 Session Data Management |
86 | |
3d92cf47 |
87 | These methods fetch data from the session storage. It can only fetch, |
88 | store or delete a single key at a time. |
89 | |
ac4892f4 |
90 | =over 4 |
91 | |
92 | =item B<fetch ( $session_id, $key )> |
93 | |
94 | =item B<store ( $session_id, $key, $data )> |
95 | |
96 | =item B<delete ( $session_id, $key )> |
97 | |
98 | =back |
99 | |
43f34c01 |
100 | =head2 Storage Management |
101 | |
ac4892f4 |
102 | =over 4 |
103 | |
104 | =item B<persist ( $session_id, $response )> |
105 | |
43f34c01 |
106 | This method will perform any data persistence nessecary to maintain |
107 | data across requests. This method is called by the L<Plack::Session> |
108 | C<finalize> method. The C<$response> is expected to be a L<Plack::Response> |
109 | instance or an object with an equivalent interface. |
110 | |
ac4892f4 |
111 | =item B<cleanup ( $session_id )> |
112 | |
43f34c01 |
113 | This method is called by the L<Plack::Session> C<expire> method and |
114 | is used to remove any session data. |
115 | |
ac4892f4 |
116 | =back |
117 | |
118 | =head1 BUGS |
119 | |
120 | All complex software has bugs lurking in it, and this module is no |
121 | exception. If you find a bug please either email me, or add the bug |
122 | to cpan-RT. |
123 | |
124 | =head1 AUTHOR |
125 | |
126 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
127 | |
128 | =head1 COPYRIGHT AND LICENSE |
129 | |
130 | Copyright 2009 Infinity Interactive, Inc. |
131 | |
132 | L<http://www.iinteractive.com> |
133 | |
134 | This library is free software; you can redistribute it and/or modify |
135 | it under the same terms as Perl itself. |
136 | |
137 | =cut |
138 | |