blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/AnyEvent/Redis.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 73 CC 2 SCAR 12.8
CC
2
Cov
0%
init
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 package Dwarf::Plugin::AnyEvent::Redis;
2 use Dwarf::Pragma;
3 use Dwarf::Util qw/add_method/;
4 use AnyEvent::Redis;
5  
6 sub init {
7 my ($class, $c, $opt) = @_;
8 $opt ||= {};
9 $opt->{default_connection} ||= 'master';
10 $opt->{on_error} ||= sub { warn @_ };
11 $opt->{on_cleanup} ||= sub { warn "Connection closed: @_" };
12  
13 add_method($c, redis => sub {
14 my ($self, $key) = @_;
15 $key ||= $opt->{default_connection};
16  
17 my $conf = $self->conf('redis')
18 or return;
19  
20 $self->{'dwarf.redis'} ||= do {
21 my $repo;
22 for my $key (keys %{ $conf }) {
23 $repo->{$key} = AnyEvent::Redis->new({
24 host => $conf->{$key}->{host},
25 port => $conf->{$key}->{port},
26 encoding => $conf->{$key}->{encoding} || 'utf8',
27 });
28 $repo->{$key}->select($conf->{$key}->{dbid} // 0);
29 }
30 $repo;
31 };
32  
33 my $redis = $self->{'dwarf.redis'};
34 return $redis->{$key} if exists $redis->{$key};
35 return;
36 });
37 }
38  
39 1;