Checking in changes prior to tagging of version 0.09_01. Changelog diff is:
[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.09_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) = @_;
18     $self->_stash->{ $session_id };
19 }
20
21 sub store {
22     my ($self, $session_id, $session) = @_;
23     $self->_stash->{ $session_id } = $session;
24 }
25
26 sub remove {
27     my ($self, $session_id) = @_;
28     delete $self->_stash->{ $session_id }
29 }
30
31 1;
32
33 __END__
34
35 =pod
36
37 =head1 NAME
38
39 Plack::Session::Store - Basic in-memory session store
40
41 =head1 SYNOPSIS
42
43   use Plack::Builder;
44   use Plack::Middleware::Session;
45   use Plack::Session::Store;
46
47   my $app = sub {
48       return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
49   };
50
51   builder {
52       enable 'Session'; # this is the defalt store
53       $app;
54   };
55
56 =head1 DESCRIPTION
57
58 This is a very basic in-memory session data store. It is volatile
59 storage and not recommended for multiprocessing environments. However
60 it is very useful for development and testing.
61
62 This should be considered the store "base" class (although
63 subclassing is not a requirement) and defines the spec for
64 all B<Plack::Session::Store::*> modules. You will only
65 need to override a couple methods if you do subclass. See
66 the other B<Plack::Session::Store::*> for examples of this.
67
68 =head1 METHODS
69
70 =over 4
71
72 =item B<new ( %params )>
73
74 No parameters are expected to this constructor.
75
76 =back
77
78 =head2 Session Data Management
79
80 These methods fetch data from the session storage. It's designed to
81 store or delete multiple keys at a time.
82
83 =over 4
84
85 =item B<fetch ( $session_id )>
86
87 =item B<store ( $session_id, $session )>
88
89 =back
90
91 =head2 Storage Management
92
93 =over 4
94
95 =item B<remove ( $session_id )>
96
97 This method is called by the L<Plack::Session> C<expire> method and
98 is used to remove any session data.
99
100 =back
101
102 =head1 BUGS
103
104 All complex software has bugs lurking in it, and this module is no
105 exception. If you find a bug please either email me, or add the bug
106 to cpan-RT.
107
108 =head1 AUTHOR
109
110 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
111
112 =head1 COPYRIGHT AND LICENSE
113
114 Copyright 2009, 2010 Infinity Interactive, Inc.
115
116 L<http://www.iinteractive.com>
117
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.
120
121 =cut
122