blib/lib/Text/APL/WithCaching.pm

filter: Statementstmt 100% 31 / 31 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 95.8% 46 / 48 SCAR 17.9
CC
6
Cov
95%
_load_cache
3.0
_process
3.0
_cache
2.0
CRAP 6.0
« blib/lib/Text/APL.pm ↑ Summary blib/lib/Text/APL/Compiler.pm »
1 package Text::APL::WithCaching;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use base 'Text::APL::Core';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub _process {
9 3 ▶ my $self = shift;
Subroutine _process: called CC=3 SCAR=11.0
10 3 my ($input, $context, $cb) = @_;
11  
12 3 ▶ if (my $cache = $self->_load_cache($context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache = $self->_load_cache($context)) 2 1 3
13 2 ▶ if ($cache->{id} ne $context->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{"id"} ne $context->id) 1 1 2
14 $cache->{sub_ref} =
15 1 $self->SUPER::_compile($cache->{code}, $context);
16 }
17  
18 2 return $cb->($self, $cache->{sub_ref});
19 }
20  
21 1 $self->SUPER::_process(@_);
22 }
23  
24 sub _compile {
25 1 ▶ my $self = shift;
Subroutine _compile: called CC=1 SCAR=0.0
26 1 my ($code, $context) = @_;
27  
28 1 my $sub_ref = $self->SUPER::_compile($code, $context);
29  
30 1 $self->_cache($code, $context, $sub_ref);
31  
32 1 return $sub_ref;
33 }
34  
35 sub _load_cache {
36 3 ▶ my $self = shift;
Subroutine _load_cache: called CC=3 SCAR=11.0
37 3 my ($context) = @_;
38  
39 3 ▶ return unless defined $context->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context->name 0 3 3
40  
41 3 ▶ return unless exists $self->{cache}->{$context->name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"cache"}{$context->name} 1 2 3
42  
43 2 return $self->{cache}->{$context->name};
44 }
45  
46 sub _cache {
47 1 ▶ my $self = shift;
Subroutine _cache: called CC=2 SCAR=7.0
48 1 my ($code, $context, $sub_ref) = @_;
49  
50 1 ▶ return unless defined $context->name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context->name 0 1 1
51  
52 1 $self->{cache}->{$context->name} = {
53 id => $context->id,
54 code => $code,
55 sub_ref => $sub_ref
56 };
57 }
58  
59 2 1;
60 __END__
« blib/lib/Text/APL.pm ↑ Summary blib/lib/Text/APL/Compiler.pm »