File Coverage

blib/lib/B/Hooks/EndOfScope/PP.pm
Criterion Covered Total %
statement 19 24 79.1
branch 2 6 33.3
condition n/a
subroutine 6 6 100.0
pod n/a
total 27 36 75.0


line stmt bran cond sub pod time code
1             package B::Hooks::EndOfScope::PP;
2             # ABSTRACT: Execute code after a scope finished compilation - PP implementation
3              
4 1     1   70283 use warnings;
  1         14  
  1         34  
5 1     1   5 use strict;
  1         2  
  1         54  
6              
7             our $VERSION = '0.25';
8              
9 1     1   6 use constant _PERL_VERSION => "$]";
  1         1  
  1         187  
10              
11             BEGIN {
12 1 50   1   6 if (_PERL_VERSION =~ /^5\.009/) {
13             # CBA to figure out where %^H got broken and which H::U::HH is sane enough
14 0         0 die "By design B::Hooks::EndOfScope does not operate in pure-perl mode on perl 5.9.X\n"
15             }
16             elsif (_PERL_VERSION < '5.010') {
17             require B::Hooks::EndOfScope::PP::HintHash;
18             *on_scope_end = \&B::Hooks::EndOfScope::PP::HintHash::on_scope_end;
19             }
20             else {
21 1         361 require B::Hooks::EndOfScope::PP::FieldHash;
22 1         47 *on_scope_end = \&B::Hooks::EndOfScope::PP::FieldHash::on_scope_end;
23             }
24             }
25              
26 1         9 use Sub::Exporter::Progressive 0.001006 -setup => {
27             exports => ['on_scope_end'],
28             groups => { default => ['on_scope_end'] },
29 1     1   423 };
  1         954  
30              
31             sub __invoke_callback {
32 1     1   2 local $@;
33 1 50       2 eval { $_[0]->(); 1 } or do {
  1         13  
  1         13  
34 0           my $err = $@;
35 0           require Carp;
36 0           Carp::cluck( (join ' ',
37             'A scope-end callback raised an exception, which can not be propagated when',
38             'B::Hooks::EndOfScope operates in pure-perl mode. Your program will CONTINUE',
39             'EXECUTION AS IF NOTHING HAPPENED AFTER THIS WARNING. Below is the complete',
40             'exception text, followed by a stack-trace of the callback execution:',
41             ) . "\n\n$err\n\r" );
42              
43 0 0         sleep 1 if -t *STDERR; # maybe a bad idea...?
44             };
45             }
46              
47             1;
48              
49             __END__