File Coverage

blib/lib/Catalyst/Plugin/Session/Store/CHI/CHI.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::Session::Store::CHI::CHI;
2              
3 1     1   14594 use 5.008;
  1         3  
  1         39  
4 1     1   4 use strict;
  1         1  
  1         28  
5 1     1   3 use warnings;
  1         4  
  1         30  
6              
7 1     1   451 use MRO::Compat;
  1         2182  
  1         30  
8              
9 1     1   6 use base qw( Class::Data::Inheritable Catalyst::Plugin::Session::Store );
  1         1  
  1         545  
10              
11 1     1   801 use CHI;
  0            
  0            
12             use Path::Class ();
13             use File::Spec ();
14             use Catalyst::Utils ();
15             use Carp::Assert;
16              
17             __PACKAGE__->mk_classdata(qw/_session_chi_chi_storage/);
18              
19             =head1 NAME
20              
21             Catalyst::Plugin::Session::Store::CHI::CHI - Use the CHI cache handler for session storage.
22              
23             =head1 VERSION
24              
25             Version 0.002
26              
27             =cut
28              
29             our $VERSION = '0.002';
30              
31             =head1 SYNOPSIS
32              
33             This allow the CHI cache handler to be used to implement the session storage.
34              
35             It was written for a project which required Memcached as a cache in front of an Oracle database.
36             However, it should handle most things that CHI can handle.
37              
38             =head2 Example Configuration
39              
40             __PACKAGE__->config(
41              
42             'Plugin::Session' => {
43             chi_chi => {
44             driver => 'DBIC',
45             dbic_class => 'DB::Mbfl2Session',
46             l1_cache =>
47             { driver => 'Memcached::Fast', servers => ['127.0.0.1:11211'] },
48             },
49             expires => 300,
50             expires_on_backend => 1,
51             cookie_secure => 2,
52             cookie_expires => 0 # 0 is session cookie
53             },
54             );
55              
56             =head1 EXPORT
57              
58             Nothing.
59              
60             =head1 SUBROUTINES/METHODS
61              
62             =head2 METHODS
63              
64             =over 4
65              
66             =item get_session_data
67              
68             =item store_session_data
69              
70             =item delete_session_data
71              
72             =item delete_expired_sessions
73              
74             These are implementations of the required methods for a store. See
75             L<Catalyst::Plugin::Session::Store>.
76              
77             =cut
78              
79             sub get_session_data {
80             my ( $c, $sid ) = @_;
81             $c->_check_session_chi_chi_storage; #see?
82             return $c->_session_chi_chi_storage->get($sid);
83             }
84              
85             sub store_session_data {
86             my ( $c, $sid, $data ) = @_;
87             $c->_check_session_chi_chi_storage; #see?
88             return $c->_session_chi_chi_storage->set( $sid, $data );
89             }
90              
91             sub delete_session_data {
92             my ( $c, $sid ) = @_;
93             $c->_check_session_chi_chi_storage; #see?
94             return $c->_session_chi_chi_storage->remove($sid);
95             }
96              
97             sub delete_expired_sessions { return; } # unsupported
98              
99             # Dummy method.
100             ## no critic (ProhibitUnusedPrivateSubroutines)
101             sub _session_store_delegate {
102             my ($self) = @_;
103             return 1;
104             }
105             ## use critic
106              
107             =item setup_session
108              
109             Sets up the session cache file.
110              
111             =back
112              
113             =cut
114              
115             sub setup_session {
116             my $c = shift;
117              
118             return $c->maybe::next::method(@_);
119             }
120              
121             sub _check_session_chi_chi_storage {
122             my $c = shift;
123             return if $c->_session_chi_chi_storage;
124              
125             $c->_session_plugin_config->{namespace} ||= 'SessionStoreChiChi';
126             my $cfg = $c->_session_plugin_config->{chi_chi} || {};
127             $cfg->{expires_in} ||= $c->_session_plugin_config->{expires};
128              
129             if ( $cfg->{dbic_class} ) {
130             $cfg->{resultset} = $c->model( $cfg->{dbic_class} );
131             }
132              
133             for my $k (qw/driver /) {
134             assert( $cfg->{$k}, "Need session config key $k" );
135             }
136              
137             return $c->_session_chi_chi_storage( CHI->new(%$cfg) );
138             }
139              
140             =head1 AUTHOR
141              
142             Motortrak Ltd, C<< <duncan.garland at motortrak.com> >>
143              
144             =head1 BUGS
145              
146             Please report any bugs or feature requests to C<bug-catalyst-plugin-session-store-chi-chi at rt.cpan.org>, or through
147             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Session-Store-CHI-CHI>. I will be notified, and then you'll
148             automatically be notified of progress on your bug as I make changes.
149              
150              
151              
152              
153             =head1 SUPPORT
154              
155             You can find documentation for this module with the perldoc command.
156              
157             perldoc Catalyst::Plugin::Session::Store::CHI::CHI
158              
159              
160             You can also look for information at:
161              
162             =over 4
163              
164             =item * RT: CPAN's request tracker (report bugs here)
165              
166             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Session-Store-CHI-CHI>
167              
168             =item * AnnoCPAN: Annotated CPAN documentation
169              
170             L<http://annocpan.org/dist/Catalyst-Plugin-Session-Store-CHI-CHI>
171              
172             =item * CPAN Ratings
173              
174             L<http://cpanratings.perl.org/d/Catalyst-Plugin-Session-Store-CHI-CHI>
175              
176             =item * Search CPAN
177              
178             L<http://search.cpan.org/dist/Catalyst-Plugin-Session-Store-CHI-CHI/>
179              
180             =back
181              
182              
183             =head1 ACKNOWLEDGEMENTS
184              
185             This drew heavily on Catalyst::Plugin::Session::Store::CHI. In fact, it was originally
186             intended to be a subclass of Catalyst::Plugin::Session::Store::CHI.
187              
188             =head1 LICENSE AND COPYRIGHT
189              
190             Copyright 2014 Motortrak Ltd.
191              
192             This program is free software; you can redistribute it and/or modify it
193             under the terms of the the Artistic License (2.0). You may obtain a
194             copy of the full license at:
195              
196             L<http://www.perlfoundation.org/artistic_license_2_0>
197              
198             Any use, modification, and distribution of the Standard or Modified
199             Versions is governed by this Artistic License. By using, modifying or
200             distributing the Package, you accept this license. Do not use, modify,
201             or distribute the Package, if you do not accept this license.
202              
203             If your Modified Version has been derived from a Modified Version made
204             by someone other than you, you are nevertheless required to ensure that
205             your Modified Version complies with the requirements of this license.
206              
207             This license does not grant you the right to use any trademark, service
208             mark, tradename, or logo of the Copyright Holder.
209              
210             This license includes the non-exclusive, worldwide, free-of-charge
211             patent license to make, have made, use, offer to sell, sell, import and
212             otherwise transfer the Package with respect to any patent claims
213             licensable by the Copyright Holder that are necessarily infringed by the
214             Package. If you institute patent litigation (including a cross-claim or
215             counterclaim) against any party alleging that the Package constitutes
216             direct or contributory patent infringement, then this Artistic License
217             to you shall terminate on the date that such litigation is filed.
218              
219             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
220             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
221             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
222             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
223             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
224             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
225             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
226             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
227              
228              
229             =cut
230              
231             1; # End of Catalyst::Plugin::Session::Store::CHI::CHI