line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Cache::Cascade; |
4
|
1
|
|
|
1
|
|
30595
|
use Any::Moose; |
|
1
|
|
|
|
|
33682
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
494
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
138
|
|
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
|
0
|
|
0
|
1
|
0
|
eval $code; |
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
|
|
0
|
1
|
0
|
|
|
0
|
|
|
1
|
1
|
0
|
|
|
0
|
|
|
0
|
1
|
0
|
|
|
0
|
|
|
0
|
1
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
732
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
855
|
use namespace::clean -except => [qw(meta)]; |
|
1
|
|
|
|
|
19451
|
|
|
1
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has caches => ( |
19
|
|
|
|
|
|
|
isa => "ArrayRef", |
20
|
|
|
|
|
|
|
is => "rw", |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has float_hits => ( |
24
|
|
|
|
|
|
|
isa => "Bool", |
25
|
|
|
|
|
|
|
is => "rw", |
26
|
|
|
|
|
|
|
default => 0, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has set_deep => ( |
30
|
|
|
|
|
|
|
isa => "Bool", |
31
|
|
|
|
|
|
|
is => "rw", |
32
|
|
|
|
|
|
|
default => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get { |
37
|
5
|
|
|
5
|
1
|
4465
|
my ( $self, $key ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
5
|
100
|
|
|
|
26
|
if ( $self->float_hits ) { |
40
|
2
|
|
|
|
|
6
|
$self->get_and_float_result( $key, @{ $self->caches } ); |
|
2
|
|
|
|
|
13
|
|
41
|
|
|
|
|
|
|
} else { |
42
|
3
|
|
|
|
|
5
|
foreach my $cache ( @{ $self->caches } ) { |
|
3
|
|
|
|
|
12
|
|
43
|
7
|
100
|
|
|
|
42
|
if ( defined( my $res = $cache->get($key) ) ) { |
44
|
2
|
|
|
|
|
17
|
return $res; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
10
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get_and_float_result { |
53
|
6
|
|
|
6
|
1
|
15
|
my ( $self, $key, $head, @tail ) = @_; |
54
|
6
|
50
|
|
|
|
15
|
$head || return; |
55
|
|
|
|
|
|
|
|
56
|
6
|
100
|
|
|
|
16
|
if ( defined( my $res = $head->get($key) ) ) { |
|
|
50
|
|
|
|
|
|
57
|
2
|
|
|
|
|
16
|
return $res; |
58
|
|
|
|
|
|
|
} elsif ( @tail ) { |
59
|
4
|
50
|
|
|
|
48
|
if ( defined( my $res = $self->get_and_float_result( $key, @tail ) ) ) { |
60
|
4
|
|
|
|
|
12
|
$head->set( $key, $res ); |
61
|
4
|
|
|
|
|
35
|
return $res; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub set { |
69
|
2
|
|
|
2
|
1
|
1029
|
my ( $self, $key, $value, @extra ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
2
|
100
|
|
|
|
13
|
if ( $self->set_deep ) { |
72
|
1
|
|
|
|
|
3
|
$_->set($key, $value, @extra) for @{ $self->caches }; |
|
1
|
|
|
|
|
7
|
|
73
|
|
|
|
|
|
|
} else { |
74
|
1
|
|
50
|
|
|
10
|
( $self->caches->[0] || return )->set($key, $value, @extra); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
BEGIN { |
80
|
1
|
|
|
1
|
|
802
|
foreach my $method (qw(size count)) { |
81
|
2
|
|
|
|
|
7
|
_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
|
|
|
|
|
2
|
foreach my $method (qw(remove clear set_load_callback set_validate_callback)) { |
96
|
4
|
|
|
|
|
9
|
_eval <<'CODE', method => $method; |
97
|
|
|
|
|
|
|
sub [% method %] { |
98
|
|
|
|
|
|
|
my ( $self, @args ) = @_; |
99
|
|
|
|
|
|
|
$_->[% method %]( @args ) for @{ $self->caches }; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
CODE |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
3
|
foreach my $method (qw(entry exists load_callback validate_callback)) { |
105
|
4
|
|
|
|
|
9
|
_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
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable if __PACKAGE__->meta->can("make_immutable"); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__PACKAGE__; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |