blib/lib/CHI/Driver/DBIC.pm

filter: Statementstmt 45.1% 23 / 51 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 5 / 15 Podpod 100% 4 / 4 totaltotal 43.2% 32 / 74 CC 3 SCAR 9.7
CC
3
Cov
42%
fetch
6.0
remove
6.0
__ANON__
2.0
CRAP 2.6
↑ Summary
1 package CHI::Driver::DBIC;
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 2 ▶use Params::Validate qw/:all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 extends 'CHI::Driver';
9  
10 =head2 Attributes
11  
12 =over
13  
14 =item schema
15  
16 The DBIx::Class schema
17  
18 =item resultset
19  
20 The DBIx::Class ResultSet which will be use to operate on the database table.
21 Internally the calls will be $self->schema->($self->resultset) etc.
22  
23 =item column_map
24  
25 A hash ref with the keys key, data and expires_in. Used to map to the table columns.
26 Defaults to:
27  
28 {
29 key => 'id',
30 data => 'session_data',
31 expires_in => 'timestamp'
32 }
33  
34 =item expiry_calc_in
35  
36 =item expiry_calc_out
37  
38 =back
39  
40 =cut
41  
42 # has 'schema' => ( 'is' => 'ro', 'isa' => 'Object', 'required' => 1 );
43 2 has 'resultset' => ( 'is' => 'ro', 'isa' => 'Object', 'required' => 1 );
44 has 'expiry_calc_in' => (
45 'is' => 'ro',
46 'isa' => 'CodeRef',
47 default => sub {
48 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 ▶ return sub { my $expiry = shift; $expiry += time(); }
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 },
51 2 lazy => 1
52 );
53 has 'expiry_calc_out' => (
54 'is' => 'ro',
55 'isa' => 'CodeRef',
56 default => sub {
57 0 ▶ return sub { my ( $self, $expiry ); return $expiry; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 ▶ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 2 lazy => 1
60 );
61  
62 has 'column_map' => (
63 'is' => 'ro',
64 'isa' => 'HashRef',
65 default => sub {
66 return {
67 0 ▶ key => 'id',
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 data => 'session_data',
69 expires_in => 'expires'
70 };
71 }
72 2 );
73  
74 has '_rs' => (
75 'is' => 'ro',
76 'isa' => 'Object',
77 'lazy' => 1,
78 0 ▶ 'default' => sub { my $self = shift; $self->resultset; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 2 );
80  
81 =head1 NAME
82  
83 CHI::Driver::DBIC - The great new CHI::Driver::DBIC!
84  
85 =head1 VERSION
86  
87 Version 0.001_003
88  
89 =cut
90  
91 2 our $VERSION = '0.001_003';
92  
93 =head1 SYNOPSIS
94  
95 Quick summary of what the module does.
96  
97 Perhaps a little code snippet.
98  
99 use CHI::Driver::DBIC;
100  
101 my $foo = CHI::Driver::DBIC->new();
102 ...
103  
104 =head1 EXPORT
105  
106 A list of functions that can be exported. You can delete this section
107 if you don't export anything, such as for a purely object-oriented module.
108  
109 =head1 SUBROUTINES/METHODS
110  
111 =cut
112  
113 =head2 store
114  
115 =cut
116  
117 sub store {
118 0 ▶ my ( $self, $key, $data, $expires_in ) = validate_pos( @_, 1, 1, 1, 0 );
Subroutine store: not called CC=1 SCAR=6.9
Pod documented
119 0 my $cm = $self->column_map;
120 my $hr = {
121 $cm->{key} => $key,
122 0 $cm->{data} => $data
123 };
124  
125 0 $hr->{ $cm->{expires_in} } = $self->expiry_calc_in->($expires_in);
126 0 $self->_rs->update_or_create($hr);
127 0 return 1;
128 }
129  
130 =head2 fetch
131  
132 =cut
133  
134 sub fetch {
135 0 ▶ my ( $self, $key ) = validate_pos( @_, 1, 1 );
Subroutine fetch: not called CC=2 SCAR=17.9
Pod documented
136  
137 0 my $id = $self->column_map->{key};
138 0 my $result = $self->_rs->find( { $id => $key } );
139 0 ▶ return $result->session_data if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
140 0 return;
141 }
142  
143 =head2 remove
144  
145 =cut
146  
147 sub remove {
148 0 ▶ my ( $self, $key ) = validate_pos( @_, 1, 1 );
Subroutine remove: not called CC=2 SCAR=17.9
Pod documented
149 0 my $result = $self->_rs->find( { $self->column_map->{key} => $key } );
150 0 ▶ $result->delete if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
151 0 return 1;
152 }
153  
154 =head2 clear
155  
156 =cut
157  
158 sub clear {
159 0 ▶ my ($self) = validate_pos( @_, 1 );
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
160 0 $self->_rs->search( {} )->delete;
161 0 return 1;
162 }
163  
164 =head1 AUTHOR
165  
166 Motortrak Ltd, C<< <duncan.garland at motortrak.com> >>
167  
168 =head1 BUGS
169  
170 Please report any bugs or feature requests to C<bug-chi-driver-dbic at rt.cpan.org>, or through
171 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CHI-Driver-DBIC>. I will be notified, and then you'll
172 automatically be notified of progress on your bug as I make changes.
173  
174  
175  
176  
177 =head1 SUPPORT
178  
179 You can find documentation for this module with the perldoc command.
180  
181 perldoc CHI::Driver::DBIC
182  
183  
184 You can also look for information at:
185  
186 =over 4
187  
188 =item * RT: CPAN's request tracker (report bugs here)
189  
190 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CHI-Driver-DBIC>
191  
192 =item * AnnoCPAN: Annotated CPAN documentation
193  
194 L<http://annocpan.org/dist/CHI-Driver-DBIC>
195  
196 =item * CPAN Ratings
197  
198 L<http://cpanratings.perl.org/d/CHI-Driver-DBIC>
199  
200 =item * Search CPAN
201  
202 L<http://search.cpan.org/dist/CHI-Driver-DBIC/>
203  
204 =back
205  
206  
207 =head1 ACKNOWLEDGEMENTS
208  
209  
210 =head1 LICENSE AND COPYRIGHT
211  
212 Copyright 2014 Motortrak Ltd.
213  
214 This program is free software; you can redistribute it and/or modify it
215 under the terms of the the Artistic License (2.0). You may obtain a
216 copy of the full license at:
217  
218 L<http://www.perlfoundation.org/artistic_license_2_0>
219  
220 Any use, modification, and distribution of the Standard or Modified
221 Versions is governed by this Artistic License. By using, modifying or
222 distributing the Package, you accept this license. Do not use, modify,
223 or distribute the Package, if you do not accept this license.
224  
225 If your Modified Version has been derived from a Modified Version made
226 by someone other than you, you are nevertheless required to ensure that
227 your Modified Version complies with the requirements of this license.
228  
229 This license does not grant you the right to use any trademark, service
230 mark, tradename, or logo of the Copyright Holder.
231  
232 This license includes the non-exclusive, worldwide, free-of-charge
233 patent license to make, have made, use, offer to sell, sell, import and
234 otherwise transfer the Package with respect to any patent claims
235 licensable by the Copyright Holder that are necessarily infringed by the
236 Package. If you institute patent litigation (including a cross-claim or
237 counterclaim) against any party alleging that the Package constitutes
238 direct or contributory patent infringement, then this Artistic License
239 to you shall terminate on the date that such litigation is filed.
240  
241 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
242 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
243 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
244 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
245 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
246 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
247 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
248 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
249  
250  
251 =cut
252  
253 2 __PACKAGE__->meta->make_immutable;
254  
255 2 1; # End of CHI::Driver::DBIC
↑ Summary