line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Method::Cache::FastMmap; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Cache method results using Cache::FastMmap |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
55885
|
use v5.10.1; |
|
3
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
63
|
|
8
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
88
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
17
|
use base 'Exporter::Tiny'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1497
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
11615
|
use Cache::FastMmap; |
|
3
|
|
|
|
|
13499
|
|
|
3
|
|
|
|
|
103
|
|
13
|
3
|
|
|
3
|
|
1563
|
use Class::Method::Modifiers qw/ install_modifier /; |
|
3
|
|
|
|
|
4972
|
|
|
3
|
|
|
|
|
216
|
|
14
|
3
|
|
|
3
|
|
1321
|
use Object::Signature (); |
|
3
|
|
|
|
|
12542
|
|
|
3
|
|
|
|
|
855
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 'v0.3.2'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT = qw/ cache /; |
19
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub cache { |
23
|
3
|
|
|
3
|
1
|
86845
|
my ( $method, %options ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
14
|
my $target = caller; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
10
|
my $global = delete $options{cache}; |
28
|
|
|
|
|
|
|
my $prefix = delete $options{prefix} |
29
|
3
|
100
|
66
|
|
|
35
|
// ( $global ? "${target}::${method}::" : '' ); |
30
|
3
|
|
100
|
|
|
19
|
my $key_cb = delete $options{key_cb} // \&Object::Signature::signature; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
install_modifier $target, 'around', $method, sub { |
33
|
36
|
|
|
36
|
|
18035674
|
my $next = shift; |
34
|
36
|
|
|
|
|
97
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
36
|
|
66
|
|
|
124
|
state $cache = $global // Cache::FastMmap->new(%options); |
37
|
|
|
|
|
|
|
|
38
|
36
|
|
|
|
|
22546
|
my $key = $prefix . $key_cb->( [ $self, @_ ] ); |
39
|
36
|
|
|
|
|
1495
|
my $value = $cache->get($key); |
40
|
36
|
100
|
|
|
|
4753
|
unless ( defined $value ) { |
41
|
27
|
|
|
|
|
179
|
$cache->set( $key, $value = $self->$next(@_) ); |
42
|
|
|
|
|
|
|
} |
43
|
36
|
|
|
|
|
4567
|
return $value; |
44
|
3
|
|
|
|
|
35
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |