ManyCache.pm

filter: Statementstmt 100% 20 / 20 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 93.1% 27 / 29 CC 4 SCAR 7.7
CC
4
Cov
92%
register
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.2
« AnyCache/Backend.pm ↑ Summary AnyCache/Backend/Nop.pm »
1 package MojoX::Plugin::ManyCache;
2  
3 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use MojoX::Plugin::AnyCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 has 'pool';
7  
8 1 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod documented
9 1 my ($self, $app, %args) = @_;
10  
11 1 my @cache_names = @{$args{names}};
12 1 my $config = $args{config};
13  
14 1 $self->pool({});
15
16 1 foreach my $name (@cache_names) {
17 2 ▶ die "Missing cache configuration for cache '$name'" unless exists $config->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config->{$name} 0 2 2
18 2 $self->pool->{$name} = MojoX::Plugin::AnyCache->new( $config->{$name} );
19 }
20  
21 1 ▶ $app->helper(cache => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
22 1 my (undef, $name) = @_;
23 1 ▶ die "Unknown cache '$name' " unless exists $self->pool->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->pool->{$name} 0 1 1
24 1 $self->pool->{$name}
25 1 });
26 }
27  
28 2 1;
29  
30 =encoding utf8
31  
32 =head1 NAME
33  
34 MojoX::Plugin::ManyCache - Multi-Cache plugin with blocking and non-blocking support
35  
36 =head1 SYNOPSIS
37  
38 $app->plugin('MojoX::Plugin::ManyCache',
39 names => qw[ cache_one cache_two ],
40 config => {
41 cache_one => {
42 backend => 'MojoX::Plugin::AnyCache::Backend::Redis',
43 server => '127.0.0.1:6379',
44 },
45 cache_two => {
46 backend => 'MojoX::Plugin::AnyCache::Backend::Redis',
47 server => '10.1.1.1:6379',
48 }
49 }
50 );
51  
52 $app->cache('cache_one')->set('key', 'value')l
53  
54 =head1 DESCRIPTION
55  
56 MojoX::Plugin::ManyCache provides an interface to multiple AnyCache instances.
« AnyCache/Backend.pm ↑ Summary AnyCache/Backend/Nop.pm »