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