line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::APL::WithCaching; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use base 'Text::APL::Core'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
680
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _process { |
9
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
10
|
3
|
|
|
|
|
6
|
my ($input, $context, $cb) = @_; |
11
|
|
|
|
|
|
|
|
12
|
3
|
100
|
|
|
|
8
|
if (my $cache = $self->_load_cache($context)) { |
13
|
2
|
100
|
|
|
|
7
|
if ($cache->{id} ne $context->id) { |
14
|
|
|
|
|
|
|
$cache->{sub_ref} = |
15
|
1
|
|
|
|
|
4
|
$self->SUPER::_compile($cache->{code}, $context); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
9
|
return $cb->($self, $cache->{sub_ref}); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
7
|
$self->SUPER::_process(@_); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _compile { |
25
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
26
|
1
|
|
|
|
|
10
|
my ($code, $context) = @_; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
7
|
my $sub_ref = $self->SUPER::_compile($code, $context); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
6
|
$self->_cache($code, $context, $sub_ref); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
4
|
return $sub_ref; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _load_cache { |
36
|
3
|
|
|
3
|
|
3
|
my $self = shift; |
37
|
3
|
|
|
|
|
7
|
my ($context) = @_; |
38
|
|
|
|
|
|
|
|
39
|
3
|
50
|
|
|
|
7
|
return unless defined $context->name; |
40
|
|
|
|
|
|
|
|
41
|
3
|
100
|
|
|
|
8
|
return unless exists $self->{cache}->{$context->name}; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
37
|
return $self->{cache}->{$context->name}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _cache { |
47
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
48
|
1
|
|
|
|
|
4
|
my ($code, $context, $sub_ref) = @_; |
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
|
|
3
|
return unless defined $context->name; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
4
|
$self->{cache}->{$context->name} = { |
53
|
|
|
|
|
|
|
id => $context->id, |
54
|
|
|
|
|
|
|
code => $code, |
55
|
|
|
|
|
|
|
sub_ref => $sub_ref |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |