File Coverage

blib/lib/Test/Stream/IPC.pm
Criterion Covered Total %
statement 51 51 100.0
branch 10 10 100.0
condition 2 2 100.0
subroutine 16 16 100.0
pod 5 7 71.4
total 84 86 97.6


line stmt bran cond sub pod time code
1             package Test::Stream::IPC;
2 99     99   983 use strict;
  99         98  
  99         2575  
3 99     99   278 use warnings;
  99         85  
  99         2035  
4              
5 99     99   292 use Config qw/%Config/;
  99         86  
  99         3035  
6 99     99   315 use Carp qw/confess carp longmess/;
  99         105  
  99         4934  
7              
8             use Test::Stream::HashBase(
9 99         542 accessors => [qw/no_fatal/],
10 99     99   684 );
  99         96  
11              
12             sub import {
13 9     9   37 my $class = shift;
14 9 100       51 return if $class eq __PACKAGE__;
15 3         7 $class->register_drivers($class);
16             }
17              
18             my @DRIVERS;
19             *register_driver = \®ister_drivers;
20             sub register_drivers {
21 5     5 1 8 my $class = shift;
22 5         4 my %seen = map {($_ => 1)} @DRIVERS;
  5         13  
23 5         6 push @DRIVERS => grep { !$seen{$_} } @_;
  7         15  
24             }
25              
26             sub drivers {
27 302 100   302 1 709 unless(@DRIVERS) {
28             # Fallback to files
29 99         35201 require Test::Stream::IPC::Files;
30 99         382 push @DRIVERS => 'Test::Stream::IPC::Files';
31             }
32              
33 302         838 return @DRIVERS;
34             }
35              
36             sub init {
37 161     161 0 188 my $class = shift;
38              
39 161         371 for my $driver ($class->drivers) {
40 161 100       878 next unless $driver->is_viable;
41 160   100     665 my $ipc = $driver->new || next;
42 159         590 return $ipc;
43             }
44              
45 2         19 die "Could not find a viable IPC driver! Aborting...\n";
46             }
47              
48             my $POLLING = 0;
49 4     4 0 19 sub polling_enabled { $POLLING }
50             sub enable_polling {
51 3 100   3 1 25 return if $POLLING++;
52 2         8 require Test::Stream::Context;
53 2     17   12 Test::Stream::Context->ON_INIT(sub { $_[0]->hub->cull });
  17         38  
54             }
55              
56             for my $meth (qw/send cull add_hub drop_hub waiting is_viable/) {
57 99     99   449 no strict 'refs';
  99         123  
  99         15149  
58             *$meth = sub {
59 6     6   26 my $thing = shift;
60 6         565 confess "'$thing' did not define the required method '$meth'."
61             };
62             }
63              
64             # Print the error and call exit. We are not using 'die' cause this is a
65             # catastophic error that should never be caught. If we get here it
66             # means some serious shit has happened in a child process, the only way
67             # to inform the parent may be to exit false.
68              
69             sub abort {
70 14     14 1 3176 my $self = shift;
71 14         35 chomp(my ($msg) = @_);
72 14         60 print STDERR "IPC Fatal Error: $msg\n";
73 14         24 print STDOUT "not ok - IPC Fatal Error\n";
74              
75 14 100       53 CORE::exit(255) unless $self->no_fatal;
76             }
77              
78             sub abort_trace {
79 4     4 1 22 my $self = shift;
80 4         6 my ($msg) = @_;
81 4         352 $self->abort(longmess($msg));
82             }
83              
84              
85             1;
86              
87             __END__