Session/Backend/Redis.pm

filter: Statementstmt 48.9% 24 / 49 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 6 / 15 Podpod 0.0% 0 / 2 totaltotal 36.1% 30 / 83 CC 8 SCAR 19.6
CC
8
Cov
38%
get
20.0
__ANON__
12.0
__ANON__
6.0
CRAP 7.1
↑ Summary Session/Role/Redis.pm »
1 #
2 # This file is part of Jedi-Plugin-Session
3 #
4 # This software is copyright (c) 2013 by celogeek <me@celogeek.com>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Jedi::Plugin::Session::Backend::Redis;
10  
11 # ABSTRACT: Backend storage for Redis
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 our $VERSION = '0.05'; # VERSION
16 2 ▶use Time::Duration::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Sereal qw/encode_sereal decode_sereal/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 has 'config' => (
22 is => 'ro',
23 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 ▶ coerce => sub { ref $_[0] eq 'HASH' ? $_[0] : {} }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
25 2 );
26  
27 has 'expires_in' => (
28 is => 'ro',
29 0 ▶ default => sub { 3 * 3600 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶ coerce => sub { parse_duration( $_[0] ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 2 );
32  
33 has 'prefix' => (
34 is => 'rw',
35 0 ▶ default => sub {''},
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 ▶ coerce => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
37 0 my $val = shift;
38 0 ▶ return 'jedi_session_' if !defined $val || !length $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and length $val 0 0 0
Condition0%0/3
defined $val and length $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and length $val
defined $val length $val
Truth table0%0/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
39 0 return 'jedi_session_' . $val . '_';
40 }
41 2 );
42  
43 2 has '_redis' => ( is => 'lazy' );
44  
45 0 ▶sub _build__redis {
Subroutine _build__redis: not called CC=1 SCAR=6.9
46 0 my ($self) = @_;
47 0 return Redis->new( %{ $self->config } );
48 }
49  
50 ## no critic (NamingConventions::ProhibitAmbiguousNames)
51 0 ▶sub get {
Subroutine get: not called CC=4 SCAR=30.0
Pod undocumented
52 0 my ( $self, $uuid ) = @_;
53 0 ▶ return if !defined $uuid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uuid 0 0 0
54 0 my $session = $self->_redis->get( $self->prefix . $uuid );
55 0 ▶ if ( defined $session ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $session) 0 0 0
56 0 ▶ return if !eval { $session = decode_sereal($session); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $session = decode_sereal($session); 1 } } 0 0 0
57 }
58 0 return $session;
59 }
60  
61 0 ▶sub set {
Subroutine set: not called CC=2 SCAR=17.9
Pod undocumented
62 0 my ( $self, $uuid, $value ) = @_;
63 0 ▶ return if !defined $uuid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uuid 0 0 0
64 0 my $session = encode_sereal($value);
65 0 $self->_redis->set( $self->prefix . $uuid, $session );
66 0 $self->_redis->expire( $self->prefix . $uuid, $self->expires_in );
67 0 return 1;
68 }
69  
70 2 1;
71  
72 __END__
↑ Summary Session/Role/Redis.pm »