blib/lib/Cache/Cascade.pm

filter: Statementstmt 49.4% 45 / 91 Branchbran 42.8% 12 / 28 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 42.1% 8 / 19 Podpod 100% 13 / 13 totaltotal 51.3% 79 / 154 SCAR 49.3
CC
28
Cov
48%
entry
10.7
exists
10.7
load_callback
10.7
CRAP 138.7
↑ Summary
1 #!/usr/bin/perl
2  
3 package Cache::Cascade;
4 1 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub _eval {
9 my ( $code, %args ) = @_;
10 $code =~ s/\[%\s*(\w+)\s*%\]/$args{$1} || die "$1 is not in eval" /ge;
11 0 ▶ eval $code;
Subroutine _sum_count: not called CC=2 SCAR=16.9
Subroutine _sum_size: not called CC=2 SCAR=16.9
Subroutine clear: not called CC=2 SCAR=16.9
Subroutine count: not called CC=1 SCAR=6.2
Subroutine entry: not called CC=3 SCAR=23.7
Subroutine exists: not called CC=3 SCAR=23.7
Subroutine load_callback: not called CC=3 SCAR=23.7
Subroutine remove: called CC=2 SCAR=16.9
Subroutine set_load_callback: not called CC=2 SCAR=16.9
Subroutine set_validate_callback: not called CC=2 SCAR=16.9
Subroutine size: not called CC=1 SCAR=6.2
Subroutine validate_callback: not called CC=3 SCAR=23.7
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 6 branches
BranchTrueFalseTotal
$head or return 0 0 0 0
$head or return 0 0 0 0
if (my $res = $cache->entry(@args)) 0 0 0
if (my $res = $cache->exists(@args)) 0 0 0
if (my $res = $cache->load_callback(@args)) 0 0 0
if (my $res = $cache->validate_callback(@args)) 0 0 0
12 }
13  
14 1 ▶use namespace::clean -except => [qw(meta)];
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = "0.05";
17  
18 1 has caches => (
19 isa => "ArrayRef",
20 is => "rw",
21 );
22  
23 1 has float_hits => (
24 isa => "Bool",
25 is => "rw",
26 default => 0,
27 );
28  
29 1 has set_deep => (
30 isa => "Bool",
31 is => "rw",
32 default => 1,
33 );
34  
35  
36 sub get {
37 5 ▶ my ( $self, $key ) = @_;
Subroutine get: called CC=4 SCAR=13.9
Pod documented
38  
39 5 ▶ if ( $self->float_hits ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->float_hits) { } 2 3 5
40 2 $self->get_and_float_result( $key, @{ $self->caches } );
41 } else {
42 3 foreach my $cache ( @{ $self->caches } ) {
43 7 ▶ if ( defined( my $res = $cache->get($key) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $res = $cache->get($key))) 2 5 7
44 2 return $res;
45 }
46 }
47  
48 1 return;
49 }
50 }
51  
52 sub get_and_float_result {
53 6 ▶ my ( $self, $key, $head, @tail ) = @_;
Subroutine get_and_float_result: called CC=5 SCAR=16.8
Pod documented
54 6 ▶ $head || return;
Branch: 1 branch
BranchTrueFalseTotal
$head or return 0 6 6
55  
56 6 ▶ if ( defined( my $res = $head->get($key) ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $res = $head->get($key))) { } 2 4 6
elsif (@tail) { } 4 0 4
57 2 return $res;
58 } elsif ( @tail ) {
59 4 ▶ if ( defined( my $res = $self->get_and_float_result( $key, @tail ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $res = $self->get_and_float_result($key, @tail))) 4 0 4
60 4 $head->set( $key, $res );
61 4 return $res;
62 }
63 }
64  
65 0 return;
66 }
67  
68 sub set {
69 2 ▶ my ( $self, $key, $value, @extra ) = @_;
Subroutine set: called CC=4 SCAR=13.9
Pod documented
70  
71 2 ▶ if ( $self->set_deep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->set_deep) { } 1 1 2
72 1 $_->set($key, $value, @extra) for @{ $self->caches };
73 } else {
74 1 ▶ ( $self->caches->[0] || return )->set($key, $value, @extra);
Condition50%1/2
$self->caches->[0] || (return)
l!l
10
MC/DC0%0/1
$self->caches->[0] || (return)
$self->caches->[0]
Truth table50%1/2
A
A= $self->caches->[0]
Aresult
11
00
75 }
76 }
77  
78  
79 BEGIN {
80 1 ▶ foreach my $method (qw(size count)) {
Subroutine BEGIN: called CC=4 SCAR=13.9
81 2 _eval <<'CODE', method => $method;
82 sub [% method %] {
83 my $self = shift;
84 return $self->_sum_[% method %]( @{ $self->caches } )
85 }
86  
87 sub _sum_[% method %] {
88 my ( $self, $head, @tail ) = @_;
89 $head || return 0;
90 $head->[% method %] + $self->_sum_[% method %]( @tail );
91 }
92 CODE
93 }
94  
95 1 foreach my $method (qw(remove clear set_load_callback set_validate_callback)) {
96 4 _eval <<'CODE', method => $method;
97 sub [% method %] {
98 my ( $self, @args ) = @_;
99 $_->[% method %]( @args ) for @{ $self->caches };
100 }
101 CODE
102 }
103  
104 1 foreach my $method (qw(entry exists load_callback validate_callback)) {
105 4 _eval <<'CODE', method => $method;
106 sub [% method %] {
107 my ( $self, @args ) = @_;
108  
109 foreach my $cache ( @{ $self->caches } ) {
110 if ( my $res = $cache->[% method %]( @args ) ) {
111 return $res;
112 }
113 }
114  
115 return;
116 }
117 CODE
118 }
119 }
120  
121 1 ▶__PACKAGE__->meta->make_immutable if __PACKAGE__->meta->can("make_immutable");
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->meta->can("make_immutable") 1 0 1
122  
123 1 __PACKAGE__;
124  
125 __END__
↑ Summary