line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Cascade; # git description: v0.06-3-g9cbe01e |
2
|
|
|
|
|
|
|
# ABSTRACT: Get/set values to/from a group of caches, with some advanced semantics. |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
88395
|
use strictures 2; |
|
2
|
|
|
|
|
2186
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
1171
|
use Moo; |
|
2
|
|
|
|
|
18436
|
|
|
2
|
|
|
|
|
6
|
|
6
|
2
|
|
|
2
|
|
2612
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
82
|
|
7
|
2
|
|
|
2
|
|
1006
|
use Types::Standard qw(ArrayRef Bool); |
|
2
|
|
|
|
|
93619
|
|
|
2
|
|
|
|
|
15
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _eval { |
10
|
20
|
|
|
20
|
|
37
|
my ( $code, %args ) = @_; |
11
|
20
|
50
|
|
|
|
81
|
$code =~ s/\[%\s*(\w+)\s*%\]/$args{$1} || die "$1 is not in eval" /ge; |
|
52
|
|
|
|
|
178
|
|
12
|
20
|
100
|
|
14
|
1
|
1294
|
eval $code; |
|
14
|
100
|
|
42
|
1
|
356
|
|
|
14
|
50
|
|
4
|
1
|
36
|
|
|
7
|
50
|
|
7
|
1
|
11
|
|
|
42
|
50
|
|
14
|
1
|
703
|
|
|
42
|
50
|
|
1
|
1
|
118
|
|
|
21
|
|
|
1
|
1
|
44
|
|
|
4
|
|
|
205
|
1
|
1052
|
|
|
4
|
|
|
2
|
1
|
4
|
|
|
4
|
|
|
2
|
1
|
49
|
|
|
7
|
|
|
21
|
|
209
|
|
|
7
|
|
|
1
|
|
6
|
|
|
7
|
|
|
|
|
81
|
|
|
14
|
|
|
|
|
24681
|
|
|
14
|
|
|
|
|
16
|
|
|
14
|
|
|
|
|
174
|
|
|
14
|
|
|
|
|
661
|
|
|
14
|
|
|
|
|
1097
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
163
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
82
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
52
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
25
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
20
|
|
|
205
|
|
|
|
|
43011
|
|
|
205
|
|
|
|
|
151
|
|
|
205
|
|
|
|
|
2290
|
|
|
2
|
|
|
|
|
50
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
417
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
25
|
|
|
21
|
|
|
|
|
6009724
|
|
|
21
|
|
|
|
|
22
|
|
|
21
|
|
|
|
|
259
|
|
|
1
|
|
|
|
|
56
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
23
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
19
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
2018
|
use namespace::autoclean; |
|
2
|
|
|
|
|
18200
|
|
|
2
|
|
|
|
|
6
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has caches => ( |
20
|
|
|
|
|
|
|
isa => ArrayRef, |
21
|
|
|
|
|
|
|
is => "rw", |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has float_hits => ( |
25
|
|
|
|
|
|
|
isa => Bool, |
26
|
|
|
|
|
|
|
is => "rw", |
27
|
|
|
|
|
|
|
default => 0, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has set_deep => ( |
31
|
|
|
|
|
|
|
isa => Bool, |
32
|
|
|
|
|
|
|
is => "rw", |
33
|
|
|
|
|
|
|
default => 1, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get { |
38
|
8
|
|
|
8
|
1
|
4083
|
my ( $self, $key ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
8
|
100
|
|
|
|
121
|
if ( $self->float_hits ) { |
41
|
2
|
|
|
|
|
14
|
$self->get_and_float_result( $key, @{ $self->caches } ); |
|
2
|
|
|
|
|
36
|
|
42
|
|
|
|
|
|
|
} else { |
43
|
6
|
|
|
|
|
923
|
foreach my $cache ( @{ $self->caches } ) { |
|
6
|
|
|
|
|
66
|
|
44
|
10
|
100
|
|
|
|
466
|
if ( defined( my $res = $cache->get($key) ) ) { |
45
|
5
|
|
|
|
|
437
|
return $res; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
7
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get_and_float_result { |
54
|
6
|
|
|
6
|
1
|
34
|
my ( $self, $key, $head, @tail ) = @_; |
55
|
6
|
50
|
|
|
|
11
|
$head || return; |
56
|
|
|
|
|
|
|
|
57
|
6
|
100
|
|
|
|
8
|
if ( defined( my $res = $head->get($key) ) ) { |
|
|
50
|
|
|
|
|
|
58
|
2
|
|
|
|
|
10
|
return $res; |
59
|
|
|
|
|
|
|
} elsif ( @tail ) { |
60
|
4
|
50
|
|
|
|
20
|
if ( defined( my $res = $self->get_and_float_result( $key, @tail ) ) ) { |
61
|
4
|
|
|
|
|
5
|
$head->set( $key, $res ); |
62
|
4
|
|
|
|
|
16
|
return $res; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub set { |
70
|
210
|
|
|
210
|
1
|
15714
|
my ( $self, $key, $value, @extra ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
210
|
100
|
|
|
|
3275
|
if ( $self->set_deep ) { |
73
|
209
|
|
|
|
|
1607
|
$_->set($key, $value, @extra) for @{ $self->caches }; |
|
209
|
|
|
|
|
2489
|
|
74
|
|
|
|
|
|
|
} else { |
75
|
1
|
|
50
|
|
|
17
|
( $self->caches->[0] || return )->set($key, $value, @extra); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
BEGIN { |
81
|
2
|
|
|
2
|
|
685
|
foreach my $method (qw(size count)) { |
82
|
4
|
|
|
|
|
9
|
_eval <<'CODE', method => $method; |
83
|
|
|
|
|
|
|
sub [% method %] { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
return $self->_sum_[% method %]( @{ $self->caches } ) |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _sum_[% method %] { |
89
|
|
|
|
|
|
|
my ( $self, $head, @tail ) = @_; |
90
|
|
|
|
|
|
|
$head || return 0; |
91
|
|
|
|
|
|
|
$head->[% method %] + $self->_sum_[% method %]( @tail ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
CODE |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
5
|
foreach my $method (qw(remove clear set_load_callback set_validate_callback)) { |
97
|
8
|
|
|
|
|
17
|
_eval <<'CODE', method => $method; |
98
|
|
|
|
|
|
|
sub [% method %] { |
99
|
|
|
|
|
|
|
my ( $self, @args ) = @_; |
100
|
|
|
|
|
|
|
$_->[% method %]( @args ) for @{ $self->caches }; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
CODE |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
4
|
foreach my $method (qw(entry exists load_callback validate_callback)) { |
106
|
8
|
|
|
|
|
13
|
_eval <<'CODE', method => $method; |
107
|
|
|
|
|
|
|
sub [% method %] { |
108
|
|
|
|
|
|
|
my ( $self, @args ) = @_; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
foreach my $cache ( @{ $self->caches } ) { |
111
|
|
|
|
|
|
|
if ( my $res = $cache->[% method %]( @args ) ) { |
112
|
|
|
|
|
|
|
return $res; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
CODE |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__PACKAGE__; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |