Commit | Line | Data |
06190e8b |
1 | package Plack::Session; |
2 | use strict; |
3 | use warnings; |
4 | |
5 | use Plack::Util::Accessor qw[ |
6 | id |
7 | store |
8 | state |
9 | ]; |
10 | |
11 | sub new { |
12 | my ($class, %params) = @_; |
ac4892f4 |
13 | my $request = delete $params{'request'}; |
14 | $params{'id'} = $params{'state'}->get_session_id( $request ); |
15 | bless { %params } => $class; |
06190e8b |
16 | } |
17 | |
18 | ## Data Managment |
19 | |
20 | sub get { |
21 | my ($self, $key) = @_; |
22 | $self->store->fetch( $self->id, $key ) |
23 | } |
24 | |
25 | sub set { |
26 | my ($self, $key, $value) = @_; |
27 | $self->store->store( $self->id, $key, $value ); |
28 | } |
29 | |
30 | sub remove { |
31 | my ($self, $key) = @_; |
32 | $self->store->delete( $self->id, $key ); |
33 | } |
34 | |
35 | ## Lifecycle Management |
36 | |
37 | sub expire { |
38 | my $self = shift; |
39 | $self->store->cleanup( $self->id ); |
40 | $self->state->expire_session_id( $self->id ); |
41 | } |
42 | |
43 | sub finalize { |
bd992981 |
44 | my ($self, $response) = @_; |
45 | $self->store->persist( $self->id, $response ); |
46 | $self->state->finalize( $self->id, $response ); |
06190e8b |
47 | } |
48 | |
ac4892f4 |
49 | 1; |
50 | |
51 | __END__ |
52 | |
53 | =pod |
54 | |
55 | =head1 NAME |
56 | |
57 | Plack::Session - Middleware for session management |
58 | |
59 | =head1 SYNOPSIS |
60 | |
61 | use Plack::Session; |
62 | |
63 | =head1 DESCRIPTION |
64 | |
65 | =head1 METHODS |
66 | |
67 | =over 4 |
68 | |
69 | =item B<new ( %params )> |
70 | |
71 | =item B<id> |
72 | |
73 | =item B<state> |
74 | |
75 | =item B<store> |
76 | |
77 | =back |
78 | |
79 | =over 4 |
80 | |
81 | =item B<get ( $key )> |
82 | |
83 | =item B<set ( $key, $value )> |
84 | |
85 | =item B<remove ( $key )> |
86 | |
87 | =back |
88 | |
89 | =over 4 |
90 | |
91 | =item B<expire> |
92 | |
93 | =item B<finalize ( $response )> |
94 | |
95 | =back |
96 | |
97 | =head1 BUGS |
98 | |
99 | All complex software has bugs lurking in it, and this module is no |
100 | exception. If you find a bug please either email me, or add the bug |
101 | to cpan-RT. |
102 | |
103 | =head1 AUTHOR |
104 | |
105 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
106 | |
107 | =head1 COPYRIGHT AND LICENSE |
108 | |
109 | Copyright 2009 Infinity Interactive, Inc. |
110 | |
111 | L<http://www.iinteractive.com> |
112 | |
113 | This library is free software; you can redistribute it and/or modify |
114 | it under the same terms as Perl itself. |
115 | |
116 | =cut |
117 | |