File Coverage

blib/lib/IPC/Run/Fused/POSIX.pm
Criterion Covered Total %
statement 33 38 86.8
branch 8 16 50.0
condition 3 6 50.0
subroutine 7 7 100.0
pod 1 1 100.0
total 52 68 76.4


line stmt bran cond sub pod time code
1 304     304   6634 use 5.008003;
  304         911  
2 304     304   1014 use strict;
  304         405  
  304         7594  
3 304     304   1215 use warnings;
  304         608  
  304         17933  
4              
5             package IPC::Run::Fused::POSIX;
6              
7             our $VERSION = '1.000001';
8              
9             # ABSTRACT: Implementation of IPC::Run::Fused for POSIX-ish systems.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 304     304   134285 use IO::Handle;
  304         1358000  
  304         13477  
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   1519 use Exporter qw(import);
  304         405  
  304         6890  
40 304     304   1329 use IPC::Run::Fused qw( _fail );
  304         405  
  304         58065  
41              
42             our @EXPORT_OK = qw( run_fused );
43              
44             sub run_fused { ## no critic ( Subroutines::RequireArgUnpacking )
45              
46 15450     15450 1 83332 my ( $read_handle, @params ) = ( \shift @_, @_ );
47              
48 15450         31412 my ( $reader, $writer );
49              
50 15450 50       484673 pipe $reader, $writer or _fail('Creating Pipe');
51              
52 15450 100       10420045 if ( my $pid = fork ) {
53 15150         98133 ${$read_handle} = $reader;
  15150         195764  
54 15150         1309991 return $pid;
55             }
56              
57 300 50       43042 open *STDOUT, '>>&=', $writer->fileno or _fail('Assigning to STDOUT');
58 300 50       51287 open *STDERR, '>>&=', $writer->fileno or _fail('Assigning to STDERR');
59              
60 300 100 66     13846 if ( ref $params[0] and 'CODE' eq ref $params[0] ) {
61 100         1744 $params[0]->();
62 100         106852 exit;
63             }
64 200 50 33     2756 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         2693 my $program = $params[0];
71             ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
72 200 0       1404 exec {$program} @params or _fail('<> failed');
  200            
73 0           exit;
74             }
75              
76             1;
77              
78             __END__