blib/lib/WWW/Session/Storage/Redis.pm

filter: Statementstmt 66.6% 18 / 27 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 4 / 4 totaltotal 65.9% 29 / 44 CC 3 SCAR 8.3
CC
3
Cov
61%
save
6.0
BEGIN
2.1
retrieve
2.0
CRAP 2.3
↑ Summary
1 package WWW::Session::Storage::Redis;
2  
3 2 ▶use 5.006;
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 BEGIN {
8 2 ▶ eval "use Cache::Redis;"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
11 0 warn "You must install the Cache::Redis module from CPAN to use the redis storage engine!"
12 }
13 }
14  
15  
16 =head1 NAME
17  
18 WWW::Session::Storage::Redis - Redis storage for WWW::Session
19  
20 =head1 DESCRIPTION
21  
22 Redis backend for WWW::Session
23  
24 =head1 VERSION
25  
26 Version 0.03
27  
28 =cut
29  
30 2 our $VERSION = '0.03';
31  
32  
33 =head1 SYNOPSIS
34  
35 This module is used for storing serialized WWW::Session objects in redis
36  
37 Usage :
38  
39 use WWW::Session::Storage::Redis;
40  
41 my $storage = WWW::Session::Storage::Redis->new({ server => ["127.0.0.1:6379"] });
42 ...
43
44 $storage->save($session_id,$expires,$serialized_data);
45
46 my $serialized_data = $storage->retrive($session_id);
47  
48 =head1 SUBROUTINES/METHODS
49  
50 =head2 new
51  
52 Creates a new WWW::Session::Storage::Redis object
53  
54 This method accepts only one argument, a hashref that contains all the options
55 that will be passed to the Cache::Redis module. The mendatory key in the hash
56 is "server" which must be a scalar containing the C<redis> server we want to
57 use.
58  
59 See Cache::Redis module for more details on available options
60  
61 Example :
62  
63 my $storage = WWW::Session::Storage::Redis->new({ server => "127.0.0.1:6379" });
64  
65 =cut
66 sub new {
67 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.6
Pod documented
68 1 my $params = shift;
69
70 1 my $self = { options => $params,
71 redis => Cache::Redis->new(%$params),
72 };
73
74 0 bless $self, $class;
75
76 0 return $self;
77 }
78  
79 =head2 save
80  
81 Stores the given information into the file
82  
83 =cut
84 sub save {
85 0 ▶ my ($self,$sid,$expires,$string) = @_;
Subroutine save: not called CC=2 SCAR=17.9
Pod documented
86
87 0 ▶ return $self->{redis}->set($sid,$string,$expires == -1 ? undef : $expires );
Branch: 1 branch
BranchTrueFalseTotal
$expires == -1 ? : 0 0 0
88 }
89  
90 =head2 retrieve
91  
92 Retrieves the informations for a session, verifies that it's not expired and returns
93 the string containing the serialized data
94  
95 =cut
96 sub retrieve {
97 0 ▶ my ($self,$sid) = @_;
Subroutine retrieve: not called CC=1 SCAR=6.9
Pod documented
98  
99 0 return $self->{redis}->get($sid);
100 }
101  
102 =head2 delete
103  
104 Completely removes the session data for the given session id
105  
106 =cut
107 sub delete {
108 0 ▶ my ($self,$sid) = @_;
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
109  
110 0 $self->{redis}->remove($sid);
111 }
112  
113 =head1 AUTHOR
114  
115 Jeffrey Goff, C<< <jeffrey.goff at evozon.com> >>
116  
117 =head1 BUGS
118  
119 Please report any bugs or feature requests to C<bug-www-session-storage-redis at rt.cpan.org>, or through
120 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Session-Storage-Redis>. I will be notified, and then you'll
121 automatically be notified of progress on your bug as I make changes.
122  
123  
124  
125  
126 =head1 SUPPORT
127  
128 You can find documentation for this module with the perldoc command.
129  
130 perldoc WWW::Session::Storage::Redis
131  
132  
133 You can also look for information at:
134  
135 =over 4
136  
137 =item * RT: CPAN's request tracker (report bugs here)
138  
139 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Session-Storage-Redis>
140  
141 =item * AnnoCPAN: Annotated CPAN documentation
142  
143 L<http://annocpan.org/dist/WWW-Session-Storage-Redis>
144  
145 =item * CPAN Ratings
146  
147 L<http://cpanratings.perl.org/d/WWW-Session-Storage-Redis>
148  
149 =item * Search CPAN
150  
151 L<http://search.cpan.org/dist/WWW-Session-Storage-Redis/>
152  
153 =back
154  
155  
156 =head1 ACKNOWLEDGEMENTS
157  
158  
159 =head1 LICENSE AND COPYRIGHT
160  
161 Copyright 2015 Evozon
162  
163 This program is free software; you can redistribute it and/or modify it
164 under the terms of either: the GNU General Public License as published
165 by the Free Software Foundation; or the Artistic License.
166  
167 See http://dev.perl.org/licenses/ for more information.
168  
169  
170 =cut
171  
172 2 1; # End of WWW::Session::Storage::Redis
↑ Summary