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