bunch more docs
[catagits/Web-Session.git] / lib / Plack / Session / Store.pm
CommitLineData
06190e8b 1package Plack::Session::Store;
2use strict;
3use warnings;
4
5use Plack::Util::Accessor qw[ _stash ];
6
ac4892f4 7sub new {
8 my ($class, %params) = @_;
9 $params{'_stash'} ||= +{};
10 bless { %params } => $class;
11}
06190e8b 12
13sub fetch {
14 my ($self, $session_id, $key) = @_;
15 $self->_stash->{ $session_id }->{ $key }
16}
17
18sub store {
19 my ($self, $session_id, $key, $data) = @_;
20 $self->_stash->{ $session_id }->{ $key } = $data;
21}
22
23sub delete {
24 my ($self, $session_id, $key) = @_;
25 delete $self->_stash->{ $session_id }->{ $key };
26}
27
06190e8b 28sub cleanup {
29 my ($self, $session_id) = @_;
30 delete $self->_stash->{ $session_id }
31}
32
ac4892f4 33sub persist {
34 my ($self, $session_id, $response) = @_;
35 ()
36}
37
381;
39
40__END__
41
42=pod
43
44=head1 NAME
45
46Plack::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 65This is a very basic in-memory session data store. It is volatile
66storage and not recommended for multiprocessing environments. However
67it is very useful for development and testing.
68
69This should be considered the store "base" class (although
70subclassing is not a requirement) and defines the spec for
71all B<Plack::Session::Store::*> modules. You will only
72need to override a couple methods if you do subclass. See
73the 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 81No parameters are expected to this constructor.
82
ac4892f4 83=back
84
43f34c01 85=head2 Session Data Management
86
3d92cf47 87These methods fetch data from the session storage. It can only fetch,
88store 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 106This method will perform any data persistence nessecary to maintain
107data across requests. This method is called by the L<Plack::Session>
108C<finalize> method. The C<$response> is expected to be a L<Plack::Response>
109instance or an object with an equivalent interface.
110
ac4892f4 111=item B<cleanup ( $session_id )>
112
43f34c01 113This method is called by the L<Plack::Session> C<expire> method and
114is used to remove any session data.
115
ac4892f4 116=back
117
118=head1 BUGS
119
120All complex software has bugs lurking in it, and this module is no
121exception. If you find a bug please either email me, or add the bug
122to cpan-RT.
123
124=head1 AUTHOR
125
126Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
127
128=head1 COPYRIGHT AND LICENSE
129
130Copyright 2009 Infinity Interactive, Inc.
131
132L<http://www.iinteractive.com>
133
134This library is free software; you can redistribute it and/or modify
135it under the same terms as Perl itself.
136
137=cut
138