blib/lib/Class/Method/Cache/FastMmap.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 4 / 4 Conditioncond 71.4% 5 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 92.0% 58 / 63 CC 6 SCAR 8.3
CC
6
Cov
96%
cache
4.0
__ANON__
3.0
BEGIN
1.0
CRAP 2.3
↑ Summary
1 package Class::Method::Cache::FastMmap;
2  
3 # ABSTRACT: Cache method results using Cache::FastMmap
4  
5 3 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use base 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Cache::FastMmap;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Class::Method::Modifiers qw/ install_modifier /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Object::Signature ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 our $VERSION = 'v0.3.2';
17  
18 3 our @EXPORT = qw/ cache /;
19 3 our @EXPORT_OK = @EXPORT;
20  
21  
22 3 ▶sub cache {
Subroutine cache: called CC=4 SCAR=13.9
Pod documented
23 3 my ( $method, %options ) = @_;
24  
25 3 my $target = caller;
26  
27 3 my $global = delete $options{cache};
28 my $prefix = delete $options{prefix}
29 3 ▶ // ( $global ? "${target}::${method}::" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$global ? : 1 2 3
Condition50%1/2
delete $options{"prefix"} // ($global ? "${target}::${method}::" : "")
l!l
03
MC/DC0%0/1
delete $options{"prefix"} // ($global ? "${target}::${method}::" : "")
delete $options{"prefix"}
Truth table50%1/2
A
A= delete $options{"prefix"}
Aresult
11
00
30 3 ▶ my $key_cb = delete $options{key_cb} // \&Object::Signature::signature;
Condition100%2/2
delete $options{"key_cb"} // \&Object::Signature::signature
l!l
21
MC/DC100%1/1
delete $options{"key_cb"} // \&Object::Signature::signature
delete $options{"key_cb"}
Truth table100%2/2
A
A= delete $options{"key_cb"}
Aresult
11
00
31  
32 36 ▶ install_modifier $target, 'around', $method, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
33 36 my $next = shift;
34 36 my $self = shift;
35  
36 36 ▶ state $cache = $global // Cache::FastMmap->new(%options);
Condition66%2/3
$global // "Cache::FastMmap"->new(%options)
l!l&&r!l&&!r
120
MC/DC0%0/2
$global // "Cache::FastMmap"->new(%options)
$global "Cache::FastMmap"->new(%options)
Truth table66%2/3
A // B
A= $globalB= "Cache::FastMmap"->new(%options)
ABresult
1X1
011
000
37  
38 36 my $key = $prefix . $key_cb->( [ $self, @_ ] );
39 36 my $value = $cache->get($key);
40 36 ▶ unless ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 27 9 36
41 27 $cache->set( $key, $value = $self->$next(@_) );
42 }
43 36 return $value;
44 3 };
45  
46 }
47  
48  
49 3 1;
50  
51 __END__
↑ Summary