blib/lib/File/Spec/Memoized.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 50.0% 2 / 4 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 83.6% 51 / 61 CC 3 SCAR 4.4
CC
3
Cov
88%
__ANON__
2.0
__ANON__
2.0
flush_cache
2.0
CRAP 1.6
↑ Summary
1 package File::Spec::Memoized;
2  
3 2 ▶use 5.006_002;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.00';
7  
8 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # constants:
11 # curdir, updir, rootdir, devnull
12 #
13 # already memoized:
14 # tmpdir
15 #
16 # no memoized (no performance drain):
17 # file_name_is_absolute, case_tolerant
18  
19 2 my %cache;
20  
21 # features return a scalar
22 2 foreach my $feature(qw(
23 canonpath
24 catdir
25 catfile
26 catpath
27 abs2rel
28 rel2abs
29 )) {
30 12 ▶ my $orig = File::Spec->can($feature) or die "Oops: $feature";
Branch: 1 branch
BranchTrueFalseTotal
my $orig = "File::Spec"->can($feature) or die "Oops: $feature" 12 0 12
31  
32 12 my $fs = '$' . $feature;
33  
34 20 ▶ my $memoized = sub :method {
Subroutine __ANON__: called CC=2 SCAR=7.1
35 20 my $self = shift;
36 20 ▶ return $cache{$fs, @_} ||= $self->$orig(@_);
Condition66%2/3
$cache{join $;, $fs, @_} ||= $self->$orig(@_)
l!l&&r!l&&!r
5150
MC/DC0%0/2
$cache{join $;, $fs, @_} ||= $self->$orig(@_)
$cache{join $;, $fs, @_} $self->$orig(@_)
Truth table66%2/3
A ||= B
A= $cache{join $;, $fs, @_}B= $self->$orig(@_)
ABresult
1X1
011
000
37 12 };
38 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
39 12 *{$feature} = $memoized;
40 }
41  
42 # features return a list
43 2 foreach my $feature(qw(
44 no_upwards
45 path
46 splitpath
47 splitdir
48 )) {
49 8 ▶ my $orig = File::Spec->can($feature) or die "Oops: $feature";
Branch: 1 branch
BranchTrueFalseTotal
my $orig = "File::Spec"->can($feature) or die "Oops: $feature" 8 0 8
50  
51 8 my $fl = '@' . $feature;
52  
53 2 ▶ my $memoized = sub :method {
Subroutine __ANON__: called CC=2 SCAR=6.9
54 2 my $self = shift;
55 2 ▶ return @{ $cache{$fl, @_} ||= [$self->$orig(@_)] };
Condition100%2/2
$cache{join $;, $fl, @_} ||= [$self->$orig(@_)]
l!l
11
MC/DC100%1/1
$cache{join $;, $fl, @_} ||= [$self->$orig(@_)]
$cache{join $;, $fl, @_}
Truth table100%2/2
A
A= $cache{join $;, $fl, @_}
Aresult
11
00
56 8 };
57 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 8 *{$feature} = $memoized;
59 }
60  
61 0 ▶sub flush_cache {
Subroutine flush_cache: not called CC=1 SCAR=6.9
Pod documented
62 0 undef %cache;
63 0 return;
64 }
65  
66 0 ▶sub __cache { \%cache }
Subroutine __cache: not called CC=1 SCAR=6.9
67  
68 # Organize the class hierarchy:
69 # File::Spec -> File::Spec::Memoized -> File::Spec::$OS
70 # ^^^^^^^^^^^^^^^^^^^^
71 2 our @ISA = @File::Spec::ISA;
72 2 @File::Spec::ISA = (__PACKAGE__);
73  
74 2 1;
75 __END__
↑ Summary