File Coverage

lib/IPC/Run/Fused/POSIX.pm
Criterion Covered Total %
statement 34 39 87.1
branch 8 16 50.0
condition 3 6 50.0
subroutine 7 7 100.0
pod 1 1 100.0
total 53 69 76.8


line stmt bran cond sub pod time code
1 304     304   7052 use 5.008003;
  304         1013  
  304         11357  
2 304     304   1522 use strict;
  304         405  
  304         11154  
3 304     304   1218 use warnings;
  304         406  
  304         19063  
4              
5             package IPC::Run::Fused::POSIX;
6              
7             our $VERSION = '1.000000';
8              
9             # ABSTRACT: Implementation of IPC::Run::Fused for POSIX-ish systems.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 304     304   184853 use IO::Handle;
  304         1559616  
  304         16130  
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39 304     304   1725 use Exporter qw(import);
  304         506  
  304         8019  
40 304     304   1708 use IPC::Run::Fused qw( _fail );
  304         508  
  304         69185  
41              
42             our @EXPORT_OK = qw( run_fused );
43              
44             sub run_fused { ## no critic ( Subroutines::RequireArgUnpacking )
45              
46 15450     15450 1 76820 my ( $read_handle, @params ) = ( \shift @_, @_ );
47              
48 15450         28107 my ( $reader, $writer );
49              
50 15450 50       472258 pipe $reader, $writer or _fail('Creating Pipe');
51              
52 15450 100       11920131 if ( my $pid = fork ) {
53 15150         161065 ${$read_handle} = $reader;
  15150         220490  
54 15150         1547634 return $pid;
55             }
56              
57 300 50       47170 open *STDOUT, '>>&=', $writer->fileno or _fail('Assigning to STDOUT');
58 300 50       62298 open *STDERR, '>>&=', $writer->fileno or _fail('Assigning to STDERR');
59              
60 300 100 66     15771 if ( ref $params[0] and 'CODE' eq ref $params[0] ) {
61 100         2920 $params[0]->();
62 100         145690 exit;
63             }
64 200 50 33     4739 if ( ref $params[0] and 'SCALAR' eq ref $params[0] ) {
65 0         0 my $command = ${ $params[0] };
  0         0  
66 0 0       0 exec $command or _fail('<> failed');
67 0         0 exit;
68             }
69              
70 200         2297 my $program = $params[0];
71             ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
72 200 0       1811 exec {$program} @params or _fail('<> failed');
  200            
73 0           exit;
74             }
75              
76             1;
77              
78             __END__