File Coverage

blib/lib/Test2/IPC/Driver.pm
Criterion Covered Total %
statement 35 35 100.0
branch 8 10 80.0
condition n/a
subroutine 12 12 100.0
pod 2 4 50.0
total 57 61 93.4


line stmt bran cond sub pod time code
1             package Test2::IPC::Driver;
2 30     30   214 use strict;
  30         67  
  30         894  
3 30     30   175 use warnings;
  30         59  
  30         1305  
4              
5             our $VERSION = '1.302180';
6              
7              
8 30     30   166 use Carp qw/confess/;
  30         61  
  30         1837  
9 30     30   631 use Test2::Util::HashBase qw{no_fatal no_bail};
  30         65  
  30         250  
10              
11 30     30   776 use Test2::API qw/test2_ipc_add_driver/;
  30         65  
  30         5031  
12              
13             my %ADDED;
14             sub import {
15 7     7   89 my $class = shift;
16 7 50       29 return if $class eq __PACKAGE__;
17 7 100       32 return if $ADDED{$class}++;
18 4         21 test2_ipc_add_driver($class);
19             }
20              
21 691     691 0 1788 sub pending { -1 }
22 29     29 0 99 sub set_pending { -1 }
23              
24             for my $meth (qw/send cull add_hub drop_hub waiting is_viable/) {
25 30     30   467 no strict 'refs';
  30         90  
  30         7609  
26             *$meth = sub {
27 6     6   36 my $thing = shift;
28 6         706 confess "'$thing' did not define the required method '$meth'."
29             };
30             }
31              
32             # Print the error and call exit. We are not using 'die' cause this is a
33             # catastrophic error that should never be caught. If we get here it
34             # means some serious shit has happened in a child process, the only way
35             # to inform the parent may be to exit false.
36              
37             sub abort {
38 13     13 1 2015 my $self = shift;
39 13         50 chomp(my ($msg) = @_);
40              
41 13 100       84 $self->driver_abort($msg) if $self->can('driver_abort');
42              
43 13         88 print STDERR "IPC Fatal Error: $msg\n";
44 13 100       48 print STDOUT "Bail out! IPC Fatal Error: $msg\n" unless $self->no_bail;
45              
46 13 50       37 CORE::exit(255) unless $self->no_fatal;
47             }
48              
49             sub abort_trace {
50 4     4 1 30 my $self = shift;
51 4         11 my ($msg) = @_;
52             # Older versions of Carp do not export longmess() function, so it needs to be called with package name
53 4         419 $self->abort(Carp::longmess($msg));
54             }
55              
56             1;
57              
58             __END__