0.03 release
[catagits/Web-Session.git] / lib / Plack / Session / Store.pm
CommitLineData
06190e8b 1package Plack::Session::Store;
2use strict;
3use warnings;
4
000c696e 5our $VERSION = '0.03';
30cc0a71 6our $AUTHORITY = 'cpan:STEVAN';
7
06190e8b 8use Plack::Util::Accessor qw[ _stash ];
9
ac4892f4 10sub new {
11 my ($class, %params) = @_;
12 $params{'_stash'} ||= +{};
13 bless { %params } => $class;
14}
06190e8b 15
16sub fetch {
17 my ($self, $session_id, $key) = @_;
18 $self->_stash->{ $session_id }->{ $key }
19}
20
21sub store {
22 my ($self, $session_id, $key, $data) = @_;
23 $self->_stash->{ $session_id }->{ $key } = $data;
24}
25
26sub delete {
27 my ($self, $session_id, $key) = @_;
28 delete $self->_stash->{ $session_id }->{ $key };
29}
30
06190e8b 31sub cleanup {
32 my ($self, $session_id) = @_;
33 delete $self->_stash->{ $session_id }
34}
35
ac4892f4 36sub persist {
37 my ($self, $session_id, $response) = @_;
38 ()
39}
40
74e0eff0 41sub dump_session {
42 my ($self, $session_id) = @_;
43 $self->_stash->{ $session_id } || {};
44}
45
ac4892f4 461;
47
48__END__
49
50=pod
51
52=head1 NAME
53
54Plack::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 73This is a very basic in-memory session data store. It is volatile
74storage and not recommended for multiprocessing environments. However
75it is very useful for development and testing.
76
77This should be considered the store "base" class (although
78subclassing is not a requirement) and defines the spec for
79all B<Plack::Session::Store::*> modules. You will only
80need to override a couple methods if you do subclass. See
81the 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 89No parameters are expected to this constructor.
90
ac4892f4 91=back
92
43f34c01 93=head2 Session Data Management
94
3d92cf47 95These methods fetch data from the session storage. It can only fetch,
96store 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 114This method will perform any data persistence nessecary to maintain
115data across requests. This method is called by the L<Plack::Session>
116C<finalize> method. The C<$response> is expected to be a L<Plack::Response>
117instance or an object with an equivalent interface.
118
ac4892f4 119=item B<cleanup ( $session_id )>
120
43f34c01 121This method is called by the L<Plack::Session> C<expire> method and
122is used to remove any session data.
123
74e0eff0 124=item B<dump_session ( $session_id )>
125
126This method is mostly for debugging purposes, it will always return
127a HASH ref, even if no data is actually being stored (in which case
128the HASH ref will be empty).
129
ac4892f4 130=back
131
132=head1 BUGS
133
134All complex software has bugs lurking in it, and this module is no
135exception. If you find a bug please either email me, or add the bug
136to cpan-RT.
137
138=head1 AUTHOR
139
140Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
141
142=head1 COPYRIGHT AND LICENSE
143
000c696e 144Copyright 2009, 2010 Infinity Interactive, Inc.
ac4892f4 145
146L<http://www.iinteractive.com>
147
148This library is free software; you can redistribute it and/or modify
149it under the same terms as Perl itself.
150
151=cut
152