blib/lib/Dancer2/Plugin/Shutdown/Redis.pm

filter: Statementstmt 60.0% 18 / 30 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 40.6% 24 / 59 CC 8 SCAR 37.3
CC
8
Cov
38%
_shutdown_redis
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 41.6
↑ Summary
1 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Dancer2::Plugin::Shutdown::Redis;
4  
5 # ABSTRACT: Graceful shutdown your Dancer2 application with Redis propagation
6  
7 2 ▶use Dancer2::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Tie::Redis::Candy 1.001 qw(redis_hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 with 'Dancer2::Plugin::Role::Shutdown';
13  
14 our $VERSION = '0.002'; # VERSION
15  
16 has _redis => (
17 is => 'rw',
18 );
19  
20 0 ▶sub _shutdown_redis {
Subroutine _shutdown_redis: not called CC=8 SCAR=42.8
21 0 my $self = shift;
22 0 ▶ return $self->_redis unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
23 0 my ($redis, $key) = @_;
24 0 ▶ croak "you have specify a key" unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
25 0 ▶ if (blessed $redis and ($redis->isa('Redis') or $redis->isa('Test::Mock::Redis'))) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($redis) and $redis->isa('Redis') || $redis->isa('Test::Mock::Redis')) { } 0 0 0
elsif (defined $redis and not ref $redis) { } 0 0 0
Condition0%0/6
builtin::blessed($redis) and $redis->isa("Redis") || $redis->isa("Test::Mock::Redis")
!ll&&!rl&&r
000
$redis->isa("Redis") or $redis->isa("Test::Mock::Redis")
l!l&&r!l&&!r
000
MC/DC0%0/3
builtin::blessed($redis) and $redis->isa("Redis") || $redis->isa("Test::Mock::Redis")
builtin::blessed($redis) $redis->isa("Redis") $redis->isa("Test::Mock::Redis")
Truth table0%0/4
A and B or C
A= builtin::blessed($redis)B= $redis->isa("Redis")C= $redis->isa("Test::Mock::Redis")
ABCresult
0XX0
1000
11X1
1011
26 0 $self->_redis($redis);
27 ▶ } elsif (defined $redis and not ref $redis) {
Condition0%0/3
defined $redis and not ref $redis
!ll&&!rl&&r
000
MC/DC0%0/2
defined $redis and not ref $redis
defined $redis not ref $redis
Truth table0%0/3
A and not(B)
A= defined $redisB= not ref $redis
ABresult
0X0
100
111
28 0 $self->_redis(Redis->new(server => $redis));
29 } else {
30 0 croak("Not a Redis instance: $redis");
31 }
32 0 my $shared = redis_hash($self->_redis, $key, %{ $self->shared });
33 0 $self->_set_shared($shared);
34 0 return $self->_redis;
35 }
36  
37  
38 register shutdown_at => \&_shutdown_at;
39  
40  
41 register shutdown_session_validator => sub {
42 shift->validator(@_)
43 }, { is_global => 1 };
44  
45  
46 register shutdown_redis => sub {
47 shift->_shutdown_redis(@_)
48 }, { is_global => 1 };
49  
50 on_plugin_import {
51 my $self = shift;
52 $self->app->add_hook(
53 Dancer2::Core::Hook->new(
54 name => 'before',
55 code => sub { $self->before_hook(@_) },
56 )
57 );
58 };
59  
60 register_plugin;
61  
62 1;
63  
64 __END__
↑ Summary