blib/lib/Dancer/Plugin/Redis.pm

filter: Statementstmt 100% 31 / 31 Branchbran 50.0% 4 / 8 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 81.4% 44 / 54 CC 7 SCAR 16.5
CC
7
Cov
84%
redis
8.8
BEGIN
1.0
BEGIN
1.0
CRAP 5.2
↑ Summary
1 #
2 # This file is part of Dancer-Plugin-Redis
3 #
4 # This software is copyright (c) 2014 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 Dancer::Plugin::Redis;
10  
11 # ABSTRACT: easy database connections for Dancer applications
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.8'; # VERSION
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Redis 1.955;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 my $_settings;
22 my $_handles;
23  
24 1 ▶sub redis {
Subroutine redis: called CC=7 SCAR=21.8
25 1 my @args = @_;
26 1 my ( undef, $name ) = plugin_args(@args);
27 1 ▶ $name = "_default" if not defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 0 1
28 1 ▶ return $_handles->{$name} if exists $_handles->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_handles->{$name} 0 1 1
29  
30 1 ▶ $_settings ||= plugin_setting;
Condition33%1/3
$_settings ||= plugin_setting()
l!l&&r!l&&!r
010
MC/DC0%0/2
$_settings ||= plugin_setting()
$_settings plugin_setting()
Truth table33%1/3
A ||= B
A= $_settingsB= plugin_setting()
ABresult
1X1
011
000
31  
32 my $conf
33 = $name eq '_default'
34 ? $_settings
35 1 ▶ : $_settings->{connections}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
$name eq '_default' ? : 1 0 1
36 1 ▶ croak "$name is not defined in your redis conf, please check the doc"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conf 0 1 1
37 unless defined $conf;
38  
39 return $_handles->{$name} = Redis->new(
40 server => $conf->{server},
41 debug => $conf->{debug},
42 encoding => $conf->{encoding},
43 reconnect => $conf->{reconnect} // 60,
44 password => $conf->{password},
45 1 ▶ );
Condition50%1/2
$conf->{"reconnect"} // 60
l!l
01
MC/DC0%0/1
$conf->{"reconnect"} // 60
$conf->{"reconnect"}
Truth table50%1/2
A
A= $conf->{"reconnect"}
Aresult
11
00
46  
47 }
48  
49 2 register redis => \&redis;
50 2 register_plugin for_versions => [ 1, 2 ];
51  
52 2 1;
53  
54 __END__
↑ Summary