File Coverage

blib/lib/Data/WeakMap/Tie.pm
Criterion Covered Total %
statement 41 41 100.0
branch 7 8 87.5
condition n/a
subroutine 11 11 100.0
pod n/a
total 59 60 98.3


line stmt bran cond sub pod time code
1             package Data::WeakMap::Tie;
2              
3 1     1   470 use experimental 'declared_refs';
  1         2958  
  1         5  
4              
5 1     1   138 use strict;
  1         1  
  1         33  
6 1     1   5 use warnings;
  1         1  
  1         40  
7              
8             require Tie::Hash;
9             our @ISA = 'Tie::StdHash';
10              
11 1     1   402 use Data::WeakMap::Item::Tie;
  1         1  
  1         25  
12              
13 1     1   4 use Carp 'croak';
  1         1  
  1         35  
14 1     1   14 use Scalar::Util 'weaken';
  1         2  
  1         323  
15              
16             sub TIEHASH {
17 6     6   16 bless {}, shift;
18             }
19              
20             sub STORE {
21 113     113   5675 my ($self, $key, $value) = @_;
22              
23 113 50       183 croak 'key is not a reference,' unless ref $key ne '';
24              
25 113         211 weaken(my $c = $key);
26 113         237 my $c_tie = tie $c, 'Data::WeakMap::Item::Tie', \$c, $self, $value;
27              
28 113         337 $self->{$key} = $c_tie;
29             }
30              
31             sub FETCH {
32 14     14   1951 my ($self, $key) = @_;
33              
34 14 100       31 if (my $c_tie = $self->{$key}) {
35 13         39 return $c_tie->{value};
36             } else {
37 1         3 return undef;
38             }
39             }
40              
41             sub FIRSTKEY {
42 12     12   8417 my ($self) = @_;
43              
44 12         19 my $z = keys %$self;
45              
46 12         18 my $self_key = each %$self;
47              
48 12 100       25 return defined $self_key ? ${ $self->{$self_key}{ref_c} } : undef;
  11         31  
49             }
50              
51             sub NEXTKEY {
52 320     320   397 my ($self, $lastkey) = @_;
53              
54 320         385 my $self_key = each %$self;
55              
56 320 100       433 if (! defined $self_key) {
57 10         27 weaken(${ $_->{ref_c} }) foreach values %$self;
  319         440  
58 10         30 return undef;
59             }
60 310         290 return ${ $self->{$self_key}{ref_c} };
  310         499  
61             }
62              
63             1;