adding in the dump_session method to the Store classes
[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
74e0eff0 38sub dump_session {
39 my ($self, $session_id) = @_;
40 $self->_stash->{ $session_id } || {};
41}
42
ac4892f4 431;
44
45__END__
46
47=pod
48
49=head1 NAME
50
51Plack::Session::Store - Basic in-memory session store
52
3d92cf47 53=head1 SYNOPSIS
54
55 use Plack::Builder;
56 use Plack::Middleware::Session;
57 use Plack::Session::Store;
58
59 my $app = sub {
60 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
61 };
62
63 builder {
64 enable 'Session'; # this is the defalt store
65 $app;
66 };
67
ac4892f4 68=head1 DESCRIPTION
69
3d92cf47 70This is a very basic in-memory session data store. It is volatile
71storage and not recommended for multiprocessing environments. However
72it is very useful for development and testing.
73
74This should be considered the store "base" class (although
75subclassing is not a requirement) and defines the spec for
76all B<Plack::Session::Store::*> modules. You will only
77need to override a couple methods if you do subclass. See
78the other B<Plack::Session::Store::*> for examples of this.
79
ac4892f4 80=head1 METHODS
81
82=over 4
83
84=item B<new ( %params )>
85
3d92cf47 86No parameters are expected to this constructor.
87
ac4892f4 88=back
89
43f34c01 90=head2 Session Data Management
91
3d92cf47 92These methods fetch data from the session storage. It can only fetch,
93store or delete a single key at a time.
94
ac4892f4 95=over 4
96
97=item B<fetch ( $session_id, $key )>
98
99=item B<store ( $session_id, $key, $data )>
100
101=item B<delete ( $session_id, $key )>
102
103=back
104
43f34c01 105=head2 Storage Management
106
ac4892f4 107=over 4
108
109=item B<persist ( $session_id, $response )>
110
43f34c01 111This method will perform any data persistence nessecary to maintain
112data across requests. This method is called by the L<Plack::Session>
113C<finalize> method. The C<$response> is expected to be a L<Plack::Response>
114instance or an object with an equivalent interface.
115
ac4892f4 116=item B<cleanup ( $session_id )>
117
43f34c01 118This method is called by the L<Plack::Session> C<expire> method and
119is used to remove any session data.
120
74e0eff0 121=item B<dump_session ( $session_id )>
122
123This method is mostly for debugging purposes, it will always return
124a HASH ref, even if no data is actually being stored (in which case
125the HASH ref will be empty).
126
ac4892f4 127=back
128
129=head1 BUGS
130
131All complex software has bugs lurking in it, and this module is no
132exception. If you find a bug please either email me, or add the bug
133to cpan-RT.
134
135=head1 AUTHOR
136
137Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
138
139=head1 COPYRIGHT AND LICENSE
140
141Copyright 2009 Infinity Interactive, Inc.
142
143L<http://www.iinteractive.com>
144
145This library is free software; you can redistribute it and/or modify
146it under the same terms as Perl itself.
147
148=cut
149