WeakMap/Tie.pm

filter: Statementstmt 100% 66 / 66 Branchbran 50.0% 4 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 92.3% 85 / 92 CC 7 SCAR 5.6
CC
7
Cov
94%
DELETE
3.0
FETCH
2.0
EXISTS
2.0
CRAP 1.7
↑ Summary WeakMap/Key/Tie.pm »
1 package Data::WeakMap::Tie;
2 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = "v0.0.4";
9  
10 9 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
11 9 my ($class, $mbp) = @_;
12  
13 9 my $self = [$mbp];
14 9 weaken($self->[0]);
15  
16 9 bless $self, $class;
17 }
18  
19 231 ▶sub STORE {
Subroutine STORE: called CC=2 SCAR=6.9
20 231 my ($self, $key, $value) = @_;
21  
22 231 ▶ croak 'key argument is not a ref' if ref $key eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $key eq "" 0 231 231
23  
24 231 my $struct = ${ $_[0][0] };
25  
26 231 weaken($struct->{tied_keys}{$key} = $key);
27 231 $struct->{values}{$key} = $value;
28  
29 231 require Data::WeakMap::Key::Tie;
30 231 tie $struct->{tied_keys}{$key}, 'Data::WeakMap::Key::Tie', $struct->{dummy}, $key;
31  
32 231 return $self;
33 }
34  
35 11 ▶sub FETCH {
Subroutine FETCH: called CC=2 SCAR=7.0
36 11 my ($self, $key) = @_;
37  
38 11 ▶ croak 'key argument is not a ref' if ref $key eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $key eq "" 0 11 11
39  
40 11 my $struct = ${ $_[0][0] };
41  
42 11 return $struct->{values}{$key};
43 }
44  
45 221 ▶sub DELETE {
Subroutine DELETE: called CC=3 SCAR=11.1
46 221 my ($self, $key) = @_;
47  
48 221 ▶ croak 'key argument is not a ref' if ref $key eq '' and caller ne 'Data::WeakMap::Key::Tie';
Branch: 1 branch
BranchTrueFalseTotal
if ref $key eq "" and caller ne "Data::WeakMap::Key::Tie" 0 221 221
Condition66%2/3
ref $key eq "" and caller ne "Data::WeakMap::Key::Tie"
!ll&&!rl&&r
12200
MC/DC0%0/2
ref $key eq "" and caller ne "Data::WeakMap::Key::Tie"
ref $key eq "" caller ne "Data::WeakMap::Key::Tie"
Truth table66%2/3
A and B
A= ref $key eq ""B= caller ne "Data::WeakMap::Key::Tie"
ABresult
0X0
100
111
49  
50 221 my $struct = ${ $_[0][0] };
51  
52 221 my $ret = delete $struct->{values}{$key};
53 221 delete $struct->{tied_keys}{$key};
54  
55 221 return $ret;
56 }
57  
58 2 ▶sub CLEAR {
Subroutine CLEAR: called CC=2 SCAR=6.9
59 2 my ($self) = @_;
60  
61 2 my $struct = ${ $_[0][0] };
62  
63 2 %{ $struct->{$_} } = () foreach qw/ tied_keys values /;
64 }
65  
66 2 ▶sub EXISTS {
Subroutine EXISTS: called CC=2 SCAR=7.0
67 2 my ($self, $key) = @_;
68  
69 2 ▶ croak 'key argument is not a ref' if ref $key eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $key eq "" 0 2 2
70  
71 2 my $struct = ${ $_[0][0] };
72  
73 2 return exists $struct->{tied_keys}{$key};
74 }
75  
76 18 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
77 18 my ($self) = @_;
78  
79 18 my $struct = ${ $_[0][0] };
80  
81 18 my $z = keys %{ $struct->{tied_keys} };
82  
83 18 return (each %{ $struct->{tied_keys} })[1];
84 }
85  
86 331 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
87 331 my ($self, $lastkey) = @_;
88  
89 331 my $struct = ${ $_[0][0] };
90  
91 331 weaken($struct->{tied_keys}{$lastkey});
92  
93 331 return (each %{ $struct->{tied_keys} })[1];
94 }
95  
96 5 ▶sub SCALAR {
Subroutine SCALAR: called CC=1 SCAR=0.0
97 5 my ($self) = @_;
98  
99 5 my $struct = ${ $_[0][0] };
100  
101 5 return scalar %{ $struct->{tied_keys} };
102 }
103  
104 1 1;
↑ Summary WeakMap/Key/Tie.pm »