File Coverage

blib/lib/Data/WeakMap/Item/Tie.pm
Criterion Covered Total %
statement 19 22 86.3
branch 0 2 0.0
condition 1 2 50.0
subroutine 6 7 85.7
pod n/a
total 26 33 78.7


line stmt bran cond sub pod time code
1             package Data::WeakMap::Item::Tie;
2              
3 1     1   6 use strict;
  1         2  
  1         24  
4 1     1   4 use warnings;
  1         2  
  1         31  
5              
6 1     1   5 use Scalar::Util 'weaken';
  1         16  
  1         219  
7              
8             sub TIESCALAR {
9 113     113   154 my ($class, $ref_c, $hash, $value) = @_;
10              
11 113         325 my $thing = {
12             ref_c => $ref_c,
13             key => "$$ref_c",
14             value => $value,
15             };
16 113         254 weaken($thing->{hash} = $hash);
17              
18 113         274 bless $thing, $class;
19             }
20              
21             sub STORE {
22 113     113   4253 my ($self, $value) = @_;
23              
24 113   50     164 my $hash = $self->{hash} // return; # is 'return' needed? the test still fails sometimes
25 113         244 delete $hash->{ $self->{key} };
26             }
27              
28             sub FETCH {
29 321     321   390 my ($self) = @_;
30              
31 321         317 return ${ $self->{ref_c} };
  321         737  
32             }
33              
34             sub DESTROY {
35             # avoid random error of type: "Can't call method "STORE" on an undefined value during global destruction."
36 0 0   0     if (${^GLOBAL_PHASE} eq 'DESTRUCT') {
37 0           untie ${ shift()->{ref_c} };
  0            
38             }
39             }
40              
41             1;