bunch more docs
[catagits/Web-Session.git] / lib / Plack / Session / Store.pm
1 package Plack::Session::Store;
2 use strict;
3 use warnings;
4
5 use Plack::Util::Accessor qw[ _stash ];
6
7 sub new {
8     my ($class, %params) = @_;
9     $params{'_stash'} ||= +{};
10     bless { %params } => $class;
11 }
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
28 sub cleanup {
29     my ($self, $session_id) = @_;
30     delete $self->_stash->{ $session_id }
31 }
32
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
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
63 =head1 DESCRIPTION
64
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
75 =head1 METHODS
76
77 =over 4
78
79 =item B<new ( %params )>
80
81 No parameters are expected to this constructor.
82
83 =back
84
85 =head2 Session Data Management
86
87 These methods fetch data from the session storage. It can only fetch,
88 store or delete a single key at a time.
89
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
100 =head2 Storage Management
101
102 =over 4
103
104 =item B<persist ( $session_id, $response )>
105
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
111 =item B<cleanup ( $session_id )>
112
113 This method is called by the L<Plack::Session> C<expire> method and
114 is used to remove any session data.
115
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