File Coverage

blib/lib/Proc/ChildError.pm
Criterion Covered Total %
statement 26 26 100.0
branch 14 14 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 45 45 100.0


line stmt bran cond sub pod time code
1             package Proc::ChildError;
2              
3             our $DATE = '2014-11-18'; # DATE
4             our $VERSION = '0.02'; # VERSION
5              
6 1     1   16821 use 5.010001;
  1         3  
  1         38  
7 1     1   5 use strict;
  1         2  
  1         29  
8 1     1   4 use warnings;
  1         4  
  1         217  
9              
10             require Exporter;
11             our @ISA = qw(Exporter);
12             our @EXPORT_OK = qw(explain_child_error);
13              
14             sub explain_child_error {
15 6     6 1 17 my $opts;
16 6 100       21 if (ref($_[0]) eq 'HASH') {
17 1         4 $opts = shift;
18             } else {
19 5         11 $opts = {};
20             }
21              
22 6         7 my ($num, $str);
23 6 100       12 if (defined $_[0]) {
24 5         6 $num = $_[0];
25 5         6 $str = $_[1];
26             } else {
27 1         7 $num = $?;
28 1         12 $str = $!;
29             }
30              
31 6         10 my $prefix = "";
32 6 100       15 if (defined $opts->{prog}) {
33 1         3 $prefix = "$opts->{prog} ";
34             }
35              
36 6 100       19 if ($num == -1) {
    100          
37 2 100       37 return "${prefix}failed to execute: ".($str ? "$str ":"")."($num)";
38             } elsif ($num & 127) {
39 2 100       26 return sprintf(
40             "${prefix}died with signal %d, %s coredump",
41             ($num & 127),
42             (($num & 128) ? 'with' : 'without'));
43             } else {
44 2         20 return sprintf("${prefix}exited with code %d", $num >> 8);
45             }
46             }
47              
48             1;
49             # ABSTRACT: Explain process child error
50              
51             __END__