b742d0da5311e9713eb6857b319078272c1b64e1
[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 DESCRIPTION
49
50 =head1 METHODS
51
52 =over 4
53
54 =item B<new ( %params )>
55
56 =back
57
58 =head2 Session Data Management
59
60 =over 4
61
62 =item B<fetch ( $session_id, $key )>
63
64 =item B<store ( $session_id, $key, $data )>
65
66 =item B<delete ( $session_id, $key )>
67
68 =back
69
70 =head2 Storage Management
71
72 =over 4
73
74 =item B<persist ( $session_id, $response )>
75
76 This method will perform any data persistence nessecary to maintain
77 data across requests. This method is called by the L<Plack::Session>
78 C<finalize> method. The C<$response> is expected to be a L<Plack::Response>
79 instance or an object with an equivalent interface.
80
81 =item B<cleanup ( $session_id )>
82
83 This method is called by the L<Plack::Session> C<expire> method and
84 is used to remove any session data.
85
86 =back
87
88 =head1 BUGS
89
90 All complex software has bugs lurking in it, and this module is no
91 exception. If you find a bug please either email me, or add the bug
92 to cpan-RT.
93
94 =head1 AUTHOR
95
96 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
97
98 =head1 COPYRIGHT AND LICENSE
99
100 Copyright 2009 Infinity Interactive, Inc.
101
102 L<http://www.iinteractive.com>
103
104 This library is free software; you can redistribute it and/or modify
105 it under the same terms as Perl itself.
106
107 =cut
108