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