File Coverage

blib/lib/Devel/GlobalDestruction.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 19 19 100.0


line stmt bran cond sub pod time code
1             package Devel::GlobalDestruction;
2              
3 2     2   2025 use strict;
  2         3  
  2         77  
4 2     2   15 use warnings;
  2         11  
  2         139  
5              
6             our $VERSION = '0.13';
7              
8 2         23 use Sub::Exporter::Progressive -setup => {
9             exports => [ qw(in_global_destruction) ],
10             groups => { default => [ -all ] },
11 2     2   2386 };
  2         2325  
12              
13             # we run 5.14+ - everything is in core
14             #
15             if (defined ${^GLOBAL_PHASE}) {
16 14     14 1 1738 eval 'sub in_global_destruction () { ${^GLOBAL_PHASE} eq q[DESTRUCT] }; 1'
17             or die $@;
18             }
19             # try to load the xs version if it was compiled
20             #
21             elsif (eval {
22             require Devel::GlobalDestruction::XS;
23 2     2   316 no warnings 'once';
  2         3  
  2         180  
24             *in_global_destruction = \&Devel::GlobalDestruction::XS::in_global_destruction;
25             1;
26             }) {
27             # the eval already installed everything, nothing to do
28             }
29             else {
30             # internally, PL_main_cv is set to Nullcv immediately before entering
31             # global destruction and we can use B to detect that. B::main_cv will
32             # only ever be a B::CV or a B::SPECIAL that is a reference to 0
33             require B;
34             eval 'sub in_global_destruction () { ${B::main_cv()} == 0 }; 1'
35             or die $@;
36             }
37              
38             1; # keep require happy
39              
40              
41             __END__