File Coverage

blib/lib/Error/Wait.pm
Criterion Covered Total %
statement 32 37 86.4
branch 5 8 62.5
condition n/a
subroutine 12 13 92.3
pod 0 1 0.0
total 49 59 83.0


line stmt bran cond sub pod time code
1             #
2             # Error/Wait.pm
3             #
4             # $Author: grazz $
5             # $Date: 2003/12/23 16:32:42 $
6             #
7              
8             package Error::Wait;
9              
10 1     1   776 use 5.006;
  1         3  
  1         62  
11             our $VERSION = '0.05';
12              
13 1     1   5 use strict;
  1         2  
  1         32  
14 1     1   14 use warnings;
  1         2  
  1         34  
15              
16 1     1   1327 use POSIX;
  1         9536  
  1         8  
17 1     1   3699 use Config;
  1         2  
  1         187  
18              
19             our $ERR; # alias to original $?
20              
21 1     1   4 sub TIESCALAR { bless [], shift }
22 5     5   14775 sub FETCH { return $_[0] }
23 2     2   10 sub STORE { $ERR = $_[1] }
24              
25             use overload '""' => \&stringify,
26 2     2   20 '0+' => sub { $ERR },
27 0     0   0 bool => sub { $ERR },
28 1     1   6 fallback => 1;
  1         2  
  1         215  
29              
30             my @names = split ' ', $Config{sig_name};
31              
32             sub stringify {
33 3 100   3 0 376 return $! if $ERR < 0;
34              
35 2 100       31 if (WIFEXITED($ERR)) {
36 1         7 my $status = WEXITSTATUS($ERR);
37 1         28 return "Exited: $status";
38             }
39 1 50       12 if (WIFSIGNALED($ERR)) {
40 1         7 my $sig = WTERMSIG($ERR);
41 1         16 return "Killed: $names[$sig]";
42             }
43 0 0         if (WIFSTOPPED($ERR)) {
44 0           my $sig = WSTOPSIG($ERR);
45 0           return "Stopped: $names[$sig]";
46             }
47              
48 0           return $ERR; # shouldn't get here
49             }
50              
51             #
52             # the WIF* macros aren't really as portable as "$? >> 8"
53             #
54             eval { WIFEXITED(0) };
55             if ($@) {
56 1     1   300 no warnings 'redefine';
  1         2  
  1         180  
57             *WIFEXITED = sub { 0 == ($_[0] & 0xff) };
58             *WEXITSTATUS = sub { $_[0] >> 8 };
59             *WIFSIGNALED = sub { $_[0] & 0xff };
60             *WTERMSIG = sub { $_[0] & 0xff };
61             }
62              
63             #
64             # save the original $? and get it out of harm's way
65             #
66             (*ERR, *?) = \($?, $ERR);
67             tie $?, __PACKAGE__;
68              
69             1;
70              
71             __END__