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