| 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
Condition50%1/2
delete $options{"prefix"} // ($global ? "${target}::${method}::" : "")
MC/DC0%0/1
delete $options{"prefix"} // ($global ? "${target}::${method}::" : "")
delete $options{"prefix"}
Truth table50%1/2
A
A= delete $options{"prefix"}
| |||||||||||||||||||||
| 30 | 3 | ▶ | my $key_cb = delete $options{key_cb} // \&Object::Signature::signature; | ||||||||||||||||||
|
Condition100%2/2
delete $options{"key_cb"} // \&Object::Signature::signature
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"}
| |||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 36 | my $key = $prefix . $key_cb->( [ $self, @_ ] ); | |||||||||||||||||||
| 39 | 36 | my $value = $cache->get($key); | |||||||||||||||||||
| 40 | 36 | ▶ | unless ( defined $value ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||