WithCache.pm

filter: Statementstmt 85.4% 41 / 48 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 79.1% 53 / 67 CC 5 SCAR 8.2
CC
5
Cov
82%
__ANON__
4.1
BEGIN
2.0
with_cache
2.0
CRAP 2.3
« WithCache/Backend/Cache/FileCache.pm ↑ Summary WithCache/Backend/Cache/FastMmap.pm »
1  
2 package MooseX::WithCache;
3 5 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use constant DEBUG => $ENV{MOOSEX_WITHCACHE_DEBUG} ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MOOSEX_WITHCACHE_DEBUG'} ? : 0 5 5
5 5 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Class::Load qw/load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 our $VERSION = '0.01007';
8 4 our $AUTHORITY = 'cpan:DMAKI';
9 4 my %BACKENDS;
10  
11 # This is solely for backwards compatibility
12 5 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 Moose::Exporter->setup_import_methods(
14 with_caller => [ 'with_cache' ],
15 );
16  
17 0 ▶sub with_cache {
Subroutine with_cache: not called CC=1 SCAR=6.9
Pod undocumented
18 0 my ($caller, $name, %args) = @_;
19  
20 0 Carp::carp("use of with_cache for MooseX::WithCache is now deprecated. Use parameterized roles directly");
21  
22 0 Moose::Util::apply_all_roles(
23 $caller,
24 __PACKAGE__, {
25 %args,
26 name => $name,
27 }
28 );
29 }
30  
31 4 parameter backend => (
32 isa => 'Str',
33 required => 1,
34 default => 'Cache::Memcached',
35 );
36  
37 4 parameter name => (
38 isa => 'Str',
39 required => 1,
40 default => 'cache'
41 );
42  
43 2 ▶role {
Subroutine __ANON__: called CC=4 SCAR=14.2
44 2 my $p = shift;
45  
46 2 my $name = $p->name;
47 2 my $backend_class = $p->backend;
48  
49 2 ▶ if ($backend_class !~ s/^\+//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($backend_class =~ s/^\+//) 2 0 2
50 2 $backend_class = "MooseX::WithCache::Backend::$backend_class";
51 }
52 2 load_class($backend_class);
53 2 my $backend = $BACKENDS{ $backend_class };
54 2 ▶ if (! $backend ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($backend) 2 0 2
55 2 $backend = $backend_class->new();
56 2 $BACKENDS{ $backend_class } = $backend;
57 }
58  
59 2 has $name => (
60 is => 'rw',
61 isa => $backend->cache_type(),
62 coerce => $backend->can_coerce(),
63 );
64  
65 2 has cache_disabled => (
66 is => 'rw',
67 isa => 'Bool',
68 default => 0
69 );
70  
71 # key generator generates the appropriate cache key from given key(s).
72 2 has cache_key_generator => (
73 is => 'rw',
74 does => 'MooseX::WithCache::KeyGenerator',
75 );
76  
77 2 ▶ method __get_cache => sub { $_[0]->$name };
Subroutine __ANON__: called CC=1 SCAR=0.0
78 0 ▶ method cache_debug => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine cache_debug: not called CC=1 SCAR=6.9
79 0 my $self = shift;
80 0 print STDERR "[CACHE]: @_\n";
81 2 };
82  
83 2 my $methods = $backend->methods();
84 2 ▶ while (my($method, $code) = each %$methods) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$methods) 6 2 8
85 6 method $method, $code;
86 }
87 4 };
88  
89 4 1;
90  
91 __END__
« WithCache/Backend/Cache/FileCache.pm ↑ Summary WithCache/Backend/Cache/FastMmap.pm »