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