| 1 | package Catalyst::Plugin::Session::Store::CHI::CHI; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use MRO::Compat; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use base qw( Class::Data::Inheritable Catalyst::Plugin::Session::Store ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use CHI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use Path::Class (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use File::Spec (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 2 | ▶ | use Catalyst::Utils (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 2 | ▶ | use Carp::Assert; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2 | __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 | 2 | 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 | 0 | ▶ | sub get_session_data { | ||||||||||||||||||
|
Subroutine
get_session_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 80 | 0 | my ( $c, $sid ) = @_; | |||||||||||||||||||
| 81 | 0 | $c->_check_session_chi_chi_storage; #see? | |||||||||||||||||||
| 82 | 0 | return $c->_session_chi_chi_storage->get($sid); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub store_session_data { | ||||||||||||||||||
|
Subroutine
store_session_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 86 | 0 | my ( $c, $sid, $data ) = @_; | |||||||||||||||||||
| 87 | 0 | $c->_check_session_chi_chi_storage; #see? | |||||||||||||||||||
| 88 | 0 | return $c->_session_chi_chi_storage->set( $sid, $data ); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | sub delete_session_data { | ||||||||||||||||||
|
Subroutine
delete_session_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 92 | 0 | my ( $c, $sid ) = @_; | |||||||||||||||||||
| 93 | 0 | $c->_check_session_chi_chi_storage; #see? | |||||||||||||||||||
| 94 | 0 | return $c->_session_chi_chi_storage->remove($sid); | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | ▶ | sub delete_expired_sessions { return; } # unsupported | ||||||||||||||||||
|
Subroutine
delete_expired_sessions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | # Dummy method. | ||||||||||||||||||||
| 100 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||
| 101 | 0 | ▶ | sub _session_store_delegate { | ||||||||||||||||||
|
Subroutine
_session_store_delegate: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 102 | 0 | my ($self) = @_; | |||||||||||||||||||
| 103 | 0 | 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 | 0 | ▶ | sub setup_session { | ||||||||||||||||||
|
Subroutine
setup_session: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 116 | 0 | my $c = shift; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | return $c->maybe::next::method(@_); | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 0 | ▶ | sub _check_session_chi_chi_storage { | ||||||||||||||||||
|
Subroutine
_check_session_chi_chi_storage: not called CC=7 SCAR=40.3
| |||||||||||||||||||||
| 122 | 0 | my $c = shift; | |||||||||||||||||||
| 123 | 0 | ▶ | return if $c->_session_chi_chi_storage; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | $c->_session_plugin_config->{namespace} ||= 'SessionStoreChiChi'; | ||||||||||||||||||
|
Condition0%0/2
$c->_session_plugin_config->{"namespace"} ||= "SessionStoreChiChi"
MC/DC0%0/1
$c->_session_plugin_config->{"namespace"} ||= "SessionStoreChiChi"
$c->_session_plugin_config->{"namespace"}
Truth table0%0/2
A
A= $c->_session_plugin_config->{"namespace"}
| |||||||||||||||||||||
| 126 | 0 | ▶ | my $cfg = $c->_session_plugin_config->{chi_chi} || {}; | ||||||||||||||||||
|
Condition0%0/2
$c->_session_plugin_config->{'chi_chi'} || {}
MC/DC0%0/1
$c->_session_plugin_config->{'chi_chi'} || {}
$c->_session_plugin_config->{'chi_chi'}
Truth table0%0/2
A
A= $c->_session_plugin_config->{'chi_chi'}
| |||||||||||||||||||||
| 127 | 0 | ▶ | $cfg->{expires_in} ||= $c->_session_plugin_config->{expires}; | ||||||||||||||||||
|
Condition0%0/3
$cfg->{"expires_in"} ||= $c->_session_plugin_config->{"expires"}
MC/DC0%0/2
$cfg->{"expires_in"} ||= $c->_session_plugin_config->{"expires"}
$cfg->{"expires_in"}
$c->_session_plugin_config->{"expires"}
Truth table0%0/3
A ||= B
A= $cfg->{"expires_in"}B= $c->_session_plugin_config->{"expires"}
| |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | ▶ | if ( $cfg->{dbic_class} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | 0 | $cfg->{resultset} = $c->model( $cfg->{dbic_class} ); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 0 | for my $k (qw/driver /) { | |||||||||||||||||||
| 134 | 0 | assert( $cfg->{$k}, "Need session config key $k" ); | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | 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 | 2 | 1; # End of Catalyst::Plugin::Session::Store::CHI::CHI | |||||||||||||||||||