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