EndOfScope/PP/FieldHash.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 2 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 97.2% 35 / 36 CC 4 SCAR 6.4
CC
4
Cov
100%
on_scope_end
3.0
DELETE
2.0
BEGIN
1.0
CRAP 1.9
« EndOfScope/PP.pm ↑ Summary EndOfScope/XS.pm »
1 # Implementation of a pure-perl on_scope_end for perls > 5.10
2 # (relies on Hash::Util:FieldHash)
3  
4 package # hide from pause
5 B::Hooks::EndOfScope::PP::FieldHash;
6  
7 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 our $VERSION = '0.28';
11  
12 7 ▶use Tie::Hash ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Hash::Util::FieldHash 'fieldhash';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Here we rely on a combination of several behaviors:
16 #
17 # * %^H is deallocated on scope exit, so any references to it disappear
18 # * A lost weakref in a fieldhash causes the corresponding key to be deleted
19 # * Deletion of a key on a tied hash triggers DELETE
20 #
21 # Therefore the DELETE of a tied fieldhash containing a %^H reference will
22 # be the hook to fire all our callbacks.
23  
24 7 fieldhash my %hh;
25 {
26 package # hide from pause too
27 B::Hooks::EndOfScope::PP::_TieHintHashFieldHash;
28 7 our @ISA = ( 'Tie::StdHash' ); # in Tie::Hash, in core
29 10 ▶ sub DELETE {
Subroutine DELETE: called CC=2 SCAR=6.9
30 10 my $ret = shift->SUPER::DELETE(@_);
31 10 B::Hooks::EndOfScope::PP::__invoke_callback($_) for @$ret;
32 10 $ret;
33 }
34 }
35  
36 7 ▶sub on_scope_end (&) {
Subroutine on_scope_end: called CC=3 SCAR=11.0
Pod undocumented
37 11 $^H |= 0x020000;
38  
39 11 ▶ tie(%hh, 'B::Hooks::EndOfScope::PP::_TieHintHashFieldHash')
Branch: 1 branch
BranchTrueFalseTotal
unless tied %hh 6 5 11
40 unless tied %hh;
41  
42 11 ▶ push @{ $hh{\%^H} ||= [] }, $_[0];
Condition100%2/2
$hh{\%^H} ||= []
l!l
110
MC/DC100%1/1
$hh{\%^H} ||= []
$hh{\%^H}
Truth table100%2/2
A
A= $hh{\%^H}
Aresult
11
00
43 }
44  
45 7 1;
« EndOfScope/PP.pm ↑ Summary EndOfScope/XS.pm »