Adding some additional docs and VERSION, AUTHORITY stuff
[catagits/Web-Session.git] / lib / Plack / Session / Store.pm
1 package Plack::Session::Store;
2 use strict;
3 use warnings;
4
5 our $VERSION   = '0.01';
6 our $AUTHORITY = 'cpan:STEVAN';
7
8 use Plack::Util::Accessor qw[ _stash ];
9
10 sub new {
11     my ($class, %params) = @_;
12     $params{'_stash'} ||= +{};
13     bless { %params } => $class;
14 }
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
31 sub cleanup {
32     my ($self, $session_id) = @_;
33     delete $self->_stash->{ $session_id }
34 }
35
36 sub persist {
37     my ($self, $session_id, $response) = @_;
38     ()
39 }
40
41 sub dump_session {
42     my ($self, $session_id) = @_;
43     $self->_stash->{ $session_id } || {};
44 }
45
46 1;
47
48 __END__
49
50 =pod
51
52 =head1 NAME
53
54 Plack::Session::Store - Basic in-memory session store
55
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
71 =head1 DESCRIPTION
72
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
83 =head1 METHODS
84
85 =over 4
86
87 =item B<new ( %params )>
88
89 No parameters are expected to this constructor.
90
91 =back
92
93 =head2 Session Data Management
94
95 These methods fetch data from the session storage. It can only fetch,
96 store or delete a single key at a time.
97
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
108 =head2 Storage Management
109
110 =over 4
111
112 =item B<persist ( $session_id, $response )>
113
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
119 =item B<cleanup ( $session_id )>
120
121 This method is called by the L<Plack::Session> C<expire> method and
122 is used to remove any session data.
123
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
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