blib/lib/Devel/NoGlobalSig.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 75.0% 39 / 52 CC 7 SCAR 12.9
CC
7
Cov
82%
import
6.8
DESTROY
2.0
BEGIN
1.0
CRAP 3.6
↑ Summary
1 package Devel::NoGlobalSig;
2 2 $VERSION = v0.0.1;
3  
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Devel::NoGlobalSig - croak when a global %SIG is installed
11  
12 =head1 SYNOPSIS
13  
14 This is a diagnostic tool for detecting where some code has over-written
15 a singnal handler (in the global %SIG) without using local().
16  
17 perl -MDevel::NoGlobalSig=die your_program
18  
19 =head1 ABOUT
20  
21 The installation of global signal handlers by some distant code can be
22 rather surprising. This gives you a way to detect where this happened
23 by installing an exploding subroutine in the handler slot.
24  
25 This is a diagnostic tool. It is not recommended to employ this in
26 production code (but if you find a good reason to do that, please drop
27 me a note.)
28  
29 =head1 USAGE
30  
31 Typically, you will simply want to import this from the command line,
32 e.g. when running some test which is mysteriously failing after
33 integrating two pieces of previously working code.
34  
35 perl -MDevel::NoGlobalSig=die t/never_failed_before.t
36  
37 If your frontend code installs its own global handler for good reason,
38 you'll want to import this after that happens (your handler will be
39 wrapped in a protective exploding shell.)
40  
41 BEGIN {$SIG{__DIE__} = \&my_die_handler};
42 use Devel::NoGlobalSig qw(die warn hup);
43  
44 =head2 Signal Names
45  
46 The arguments to import() may be a list of upper-case or lower-case
47 versions of the handler names. The special signals __WARN__ and __DIE__
48 may be passed as simply 'warn' and 'die', respectively.
49  
50 See L<perlipc> for details.
51  
52 =cut
53  
54 0 ▶use overload '&{}' => sub { shift->{'sub'} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
55  
56 4 ▶sub import {
Subroutine import: called CC=6 SCAR=19.1
57 4 my $package = shift;
58 4 my (@args) = @_;
59  
60 4 ▶ @args or return; # XXX croak?
Branch: 1 branch
BranchTrueFalseTotal
@args or return 3 1 4
61  
62 3 foreach my $name (@args) {
63 3 ▶ $name = '__' . $name . '__' if($name eq 'warn' or $name eq 'die');
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "warn" or $name eq "die" 3 0 3
Condition33%1/3
$name eq "warn" or $name eq "die"
l!l&&r!l&&!r
300
MC/DC0%0/2
$name eq "warn" or $name eq "die"
$name eq "warn" $name eq "die"
Truth table33%1/3
A or B
A= $name eq "warn"B= $name eq "die"
ABresult
1X1
011
000
64 3 $name = uc($name);
65  
66 my $self = {
67 name => $name,
68 0 ▶ 'sub'=> $SIG{$name} || sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
69 3 ▶ };
Condition33%1/3
$SIG{$name} || sub { }
l!l&&r!l&&!r
030
MC/DC0%0/2
$SIG{$name} || sub { }
$SIG{$name} sub { }
Truth table33%1/3
A || B
A= $SIG{$name}B= sub { }
ABresult
1X1
011
000
70 3 $SIG{$name} = bless($self, $package);
71 }
72 }
73  
74 2 my $ended = 0; END {$ended = 1};
75 3 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
76 3 ▶ return if($ended);
Branch: 1 branch
BranchTrueFalseTotal
if $ended 0 3 3
77  
78 3 my $self = shift;
79  
80 3 Carp::carp("BZZT: non-localized \$SIG{$self->{name}} assignment");
81 3 exit(1);
82 }
83  
84  
85 =head1 AUTHOR
86  
87 Eric Wilhelm @ <ewilhelm at cpan dot org>
88  
89 http://scratchcomputing.com/
90  
91 =head1 BUGS
92  
93 If you found this module on CPAN, please report any bugs or feature
94 requests through the web interface at L<http://rt.cpan.org>. I will be
95 notified, and then you'll automatically be notified of progress on your
96 bug as I make changes.
97  
98 If you pulled this development version from my /svn/, please contact me
99 directly.
100  
101 =head1 COPYRIGHT
102  
103 Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.
104  
105 =head1 NO WARRANTY
106  
107 Absolutely, positively NO WARRANTY, neither express or implied, is
108 offered with this software. You use this software at your own risk. In
109 case of loss, no person or entity owes you anything whatsoever. You
110 have been warned.
111  
112 =head1 LICENSE
113  
114 This program is free software; you can redistribute it and/or modify it
115 under the same terms as Perl itself.
116  
117 =cut
118  
119 # vi:ts=2:sw=2:et:sta
120 2 1;
↑ Summary