| 1 | package Test2::IPC::Driver; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | our $VERSION = '1.302073'; | ||
| 6 | |||
| 7 | |||
| 8 | use Carp qw/confess longmess/; | ||
| 9 | use Test2::Util::HashBase qw{no_fatal}; | ||
| 10 | |||
| 11 | use Test2::API qw/test2_ipc_add_driver/; | ||
| 12 | |||
| 13 | my %ADDED; | ||
| 14 | sub import { | ||
| 15 | my $class = shift; | ||
| 16 | return if $class eq __PACKAGE__; | ||
| 17 | return if $ADDED{$class}++; | ||
| 18 | test2_ipc_add_driver($class); | ||
| 19 | } | ||
| 20 | |||
| 21 | sub use_shm { 0 } | ||
| 22 | |||
| 23 | for my $meth (qw/send cull add_hub drop_hub waiting is_viable/) { | ||
| 24 | no strict 'refs'; | ||
| 25 | *$meth = sub { | ||
| 26 | my $thing = shift; | ||
| 27 | confess "'$thing' did not define the required method '$meth'." | ||
| 28 | }; | ||
| 29 | } | ||
| 30 | |||
| 31 | # Print the error and call exit. We are not using 'die' cause this is a | ||
| 32 | # catastrophic error that should never be caught. If we get here it | ||
| 33 | # means some serious shit has happened in a child process, the only way | ||
| 34 | # to inform the parent may be to exit false. | ||
| 35 | |||
| 36 | sub abort { | ||
| 37 | my $self = shift; | ||
| 38 | chomp(my ($msg) = @_); | ||
| 39 | print STDERR "IPC Fatal Error: $msg\n"; | ||
| 40 | print STDOUT "not ok - IPC Fatal Error\n"; | ||
| 41 | |||
| 42 | CORE::exit(255) unless $self->no_fatal; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub abort_trace { | ||
| 46 | my $self = shift; | ||
| 47 | my ($msg) = @_; | ||
| 48 | $self->abort(longmess($msg)); | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; | ||
| 52 | |||
| 53 | __END__ |