blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/Cache/Memcached/Fast.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 57 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::Cache::Memcached::Fast;
2 use Dwarf::Pragma;
3 use Dwarf::Util qw/add_method/;
4 use Cache::Memcached::Fast;
5  
6 sub init {
7 my ($class, $c, $opt) = @_;
8 $opt ||= {};
9 $opt->{compress_threshold} ||= 100_000;
10 $opt->{default_memcached} ||= 'page';
11  
12 add_method($c, memcached => sub {
13 my ($self, $key) = @_;
14 $key ||= $opt->{default_memcached};
15  
16 my $conf = $self->conf('memcached')
17 or return;
18  
19 $self->{'dwarf.memcached'} ||= do {
20 my $repo;
21 for my $key (keys %{ $conf }) {
22 $repo->{$key} = Cache::Memcached::Fast->new({
23 servers => [ { address => $conf->{$key}->{server} } ],
24 namespace => $conf->{$key}->{namespace},
25 compress_threshold => $opt->{compress_threshold},
26 });
27 }
28 $repo;
29 };
30  
31 my $memcached = $self->{'dwarf.memcached'};
32 return $memcached->{$key} if exists $memcached->{$key};
33 return;
34 });
35 }
36  
37 1;