| 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
| |||||||||||||||||||||
| 28 | 1 | ▶ | return $_handles->{$name} if exists $_handles->{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | $_settings ||= plugin_setting; | ||||||||||||||||||
|
Condition33%1/3
$_settings ||= plugin_setting()
MC/DC0%0/2
$_settings ||= plugin_setting()
$_settings
plugin_setting()
Truth table33%1/3
A ||= B
A= $_settingsB= plugin_setting()
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | my $conf | ||||||||||||||||||||
| 33 | = $name eq '_default' | ||||||||||||||||||||
| 34 | ? $_settings | ||||||||||||||||||||
| 35 | 1 | ▶ | : $_settings->{connections}->{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 1 | ▶ | croak "$name is not defined in your redis conf, please check the doc" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/1
$conf->{"reconnect"} // 60
$conf->{"reconnect"}
Truth table50%1/2
A
A= $conf->{"reconnect"}
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | register redis => \&redis; | |||||||||||||||||||
| 50 | 2 | register_plugin for_versions => [ 1, 2 ]; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 2 | 1; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||