Deep/Cache/Simple.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 5 totaltotal 85.0% 57 / 67 CC 4 SCAR 5.2
CC
4
Cov
94%
cmp
3.0
BEGIN
2.3
__ANON__
2.0
CRAP 1.7
« Deep/Array.pm ↑ Summary Deep/Cmp.pm »
1 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Test::Deep::Cache::Simple 1.205;
5  
6 41 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 41 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 BEGIN
11 41 ▶{
Subroutine BEGIN: called CC=2 SCAR=8.1
12 41 ▶ if (grep /^weaken$/, @Scalar::Util::EXPORT_FAIL)
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^weaken$/, @Scalar::Util::EXPORT_FAIL) { } 0 41 41
13 {
14 # we're running on a version of perl that has no weak refs, so we
15 # just install a no-op sub for weaken instead of importing it
16 0 ▶ *weaken = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 }
18 else
19 {
20 41 Scalar::Util->import('weaken');
21 }
22 }
23  
24 sub new
25 2662 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
26 2662 my $pkg = shift;
27  
28 2662 my $self = bless {}, $pkg;
29  
30 2662 return $self;
31 }
32  
33 sub add
34 1137 ▶{
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
35 1137 my $self = shift;
36  
37 1137 my ($d1, $d2) = @_;
38 {
39 1137 local $SIG{__DIE__};
40  
41 1137 local $@;
42  
43 # cannot weaken read only refs, no harm if we can't as they never
44 # disappear
45 1137 eval{weaken($d1)};
46 1137 eval{weaken($d2)};
47 }
48  
49 1137 $self->{fn_get_key(@_)} = [$d1, $d2];
50 }
51  
52 sub cmp
53 2506 ▶{
Subroutine cmp: called CC=3 SCAR=11.0
Pod undocumented
54 2506 my $self = shift;
55  
56 2506 my $key = fn_get_key(@_);
57 2506 my $pair = $self->{$key};
58  
59 # are both weakened refs still valid, if not delete this entry
60 2506 ▶ if (ref($pair->[0]) and ref($pair->[1]))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pair->[0] and ref $pair->[1]) { } 40 2466 2506
Condition66%2/3
ref $pair->[0] and ref $pair->[1]
!ll&&!rl&&r
2466040
MC/DC50%1/2
ref $pair->[0] and ref $pair->[1]
ref $pair->[0] ref $pair->[1]
Truth table66%2/3
A and B
A= ref $pair->[0]B= ref $pair->[1]
ABresult
0X0
100
111
61 {
62 40 return 1;
63 }
64 else
65 {
66 2466 delete $self->{$key};
67 2466 return 0;
68 }
69 }
70  
71 sub absorb
72 304 ▶{
Subroutine absorb: called CC=1 SCAR=0.0
Pod undocumented
73 304 my $self = shift;
74  
75 304 my $other = shift;
76  
77 304 @{$self}{keys %$other} = values %$other;
78 }
79  
80 sub fn_get_key
81 3643 ▶{
Subroutine fn_get_key: called CC=1 SCAR=0.0
Pod undocumented
82 3643 return join(",", sort (map {refaddr($_)} @_));
83 }
84 41 1;
85  
86 __END__
« Deep/Array.pm ↑ Summary Deep/Cmp.pm »