1 package Variable::Magic::TestGlobalDestruction;
6 # Silence possible 'used only once' warnings from Test::Builder
17 sub is_debugging_perl {
18 return $is_debugging if defined $is_debugging;
22 my $has_config_perl_v = do {
24 eval { require Config::Perl::V; 1 };
27 if ($has_config_perl_v) {
30 eval { Config::Perl::V::myconfig()->{build}{options}{DEBUGGING} };
33 if (defined $is_debugging) {
34 $source = "Config::Perl::V version $Config::Perl::V::VERSION";
38 unless (defined $is_debugging) {
43 my @fields = qw<ccflags cppflags optimize>;
45 for my $field (@fields) {
46 my $content = $Config::Config{$field};
48 while ($content =~ /(-DD?EBUGGING((?:=\S*)?))/g) {
50 if ($extra ne '=none') {
52 $source = "\$Config{$field} =~ /$1/";
58 my $maybe_is = $is_debugging ? "is" : "is NOT";
59 _diag("According to $source, this $maybe_is a debugging perl");
67 my $level = $args{level} || 1;
69 my $env_level = int($ENV{PERL_DESTRUCT_LEVEL} || 0);
70 if ($env_level >= $level) {
71 my $is_debugging = is_debugging_perl();
74 _diag("Global destruction level $env_level set by PERL_DESTRUCT_LEVEL (debugging perl)");
77 _diag("PERL_DESTRUCT_LEVEL is set to $env_level, but this perl doesn't seem to have debugging enabled");
81 my $has_perl_destruct_level = do {
84 require Perl::Destruct::Level;
85 Perl::Destruct::Level->import(level => $level);
89 if ($has_perl_destruct_level) {
90 _diag("Global destruction level $level set by Perl::Destruct::Level");