blib/lib/POE/Wheel/Run.pm

filter: Statementstmt 67.2% 380 / 565 Branchbran 55.9% 217 / 388 Conditioncond 49.6% 78 / 157 MC/DCmcdc 19.5% 18 / 92 Subroutinesub 66.6% 30 / 45 Podpod 95.2% 20 / 21 totaltotal 58.6% 743 / 1268 CC 259 SCAR 59.1
CC
259
Cov
61%
new
768.9
_exec_in_hell
240.0
_transfer_stdout_buffer
72.0
CRAP 368.6
« blib/lib/POE/Wheel/SocketFactory.pm ↑ Summary blib/lib/POE/Wheel/FollowTail.pm »
1 package POE::Wheel::Run;
2  
3 73 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 73 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 73 $VERSION = '1.370'; # NOTE - Should be #.### (three decimal places)
7  
8 73 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 73 ▶use POSIX qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 sysconf setsid _SC_OPEN_MAX ECHO ICANON IEXTEN ISIG BRKINT ICRNL
11 INPCK ISTRIP IXON CSIZE PARENB OPOST TCSANOW
12 73 );
13  
14 73 ▶use POE qw( Wheel Pipe::TwoWay Pipe::OneWay Driver::SysRW Filter::Line );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 73 push @ISA, qw(POE::Wheel);
16  
17 # http://rt.cpan.org/Ticket/Display.html?id=50068
18 # Avoid using these constants in Windows' subprocesses (actually
19 # interpreter threads). Reported in the above ticket to avoid a
20 # memory leak.
21 73 my ($STD_INPUT_HANDLE, $STD_OUTPUT_HANDLE, $STD_ERROR_HANDLE);
22  
23 73 ▶BEGIN {
Subroutine BEGIN: called CC=12 SCAR=39.3
24 73 ▶ die "$^O does not support fork()\n" if $^O eq 'MacOS';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MacOS" 0 73 73
25  
26 73 local $SIG{'__DIE__'} = 'DEFAULT';
27 73 eval { require IO::Pty; };
28 73 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 73 73
29 0 eval '
30 sub PTY_AVAILABLE () { 0 }
31 sub TIOCSWINSZ_AVAILABLE () { 0 }
32 ';
33 }
34 else {
35 73 IO::Pty->import();
36 73 eval 'sub PTY_AVAILABLE () { 1 }';
37  
38 73 eval { require IO::Tty; };
39 73 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 73 73
40 0 eval 'sub TIOCSWINSZ_AVAILABLE () { 0 }';
41 }
42 else {
43 73 IO::Tty->import('TIOCSWINSZ');
44 73 eval 'sub TIOCSWINSZ_AVAILABLE () { 1 }';
45 }
46 }
47  
48 73 ▶ if (POE::Kernel::RUNNING_IN_HELL) {
Branch: 1 branch
BranchTrueFalseTotal
if (POE::Kernel::RUNNING_IN_HELL()) 0 73 73
49 0 eval { require Win32::Console; Win32::Console->import() };
50 0 ▶ if ($@) { die "Win32::Console needed for POE::Wheel::Run on $^O:\n$@" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
51  
52 0 eval {
53 0 require Win32API::File;
54 0 Win32API::File->import("FdGetOsFHandle");
55 };
56 0 ▶ if ($@) { die "Win32API::File needed for POE::Wheel::Run on $^O:\n$@" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
57  
58 0 eval { require Win32::Process; Win32::Process->import() };
59 0 ▶ if ($@) { die "Win32::Process needed for POE::Wheel::Run on $^O:\n$@" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
60  
61 0 eval { require Win32::Job; Win32::Job->import() };
62 0 ▶ if ($@) { die "Win32::Job needed for POE::Wheel::Run on $^O:\n$@" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
63  
64 0 eval { require Win32; Win32->import() };
65 0 ▶ if ($@) { die "Win32.pm needed for POE::Wheel::Run on $^O:\n$@" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
66  
67 0 $STD_INPUT_HANDLE = STD_INPUT_HANDLE();
68 0 $STD_OUTPUT_HANDLE = STD_OUTPUT_HANDLE();
69 0 $STD_ERROR_HANDLE = STD_ERROR_HANDLE();
70 }
71  
72 # Determine the most file descriptors we can use.
73 73 my $max_open_fds;
74 73 eval {
75 73 $max_open_fds = sysconf(_SC_OPEN_MAX);
76 };
77 73 ▶ $max_open_fds = 1024 unless $max_open_fds;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_open_fds 0 73 73
78 73 eval "sub MAX_OPEN_FDS () { $max_open_fds }";
79 73 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 73 73
80 };
81  
82 # Offsets into $self.
83 sub UNIQUE_ID () { 0 }
84 sub ERROR_EVENT () { 1 }
85 sub CLOSE_EVENT () { 2 }
86 sub PROGRAM () { 3 }
87 sub CHILD_PID () { 4 }
88 sub CONDUIT_TYPE () { 5 }
89 sub IS_ACTIVE () { 6 }
90 sub CLOSE_ON_CALL () { 7 }
91 sub STDIO_TYPE () { 8 }
92  
93 sub HANDLE_STDIN () { 9 }
94 sub FILTER_STDIN () { 10 }
95 sub DRIVER_STDIN () { 11 }
96 sub EVENT_STDIN () { 12 }
97 sub STATE_STDIN () { 13 }
98 sub OCTETS_STDIN () { 14 }
99  
100 sub HANDLE_STDOUT () { 15 }
101 sub FILTER_STDOUT () { 16 }
102 sub DRIVER_STDOUT () { 17 }
103 sub EVENT_STDOUT () { 18 }
104 sub STATE_STDOUT () { 19 }
105  
106 sub HANDLE_STDERR () { 20 }
107 sub FILTER_STDERR () { 21 }
108 sub DRIVER_STDERR () { 22 }
109 sub EVENT_STDERR () { 23 }
110 sub STATE_STDERR () { 24 }
111  
112 sub MSWIN32_GROUP_PID () { 25 }
113  
114 # Used to work around a bug in older perl versions.
115 0 ▶sub CRIMSON_SCOPE_HACK ($) { 0 }
Subroutine CRIMSON_SCOPE_HACK: not called CC=1 SCAR=6.9
Pod undocumented
116  
117 #------------------------------------------------------------------------------
118  
119 379 ▶sub new {
Subroutine new: called CC=137 SCAR=66.4
Pod documented
120 379 my $type = shift;
121 379 ▶ croak "$type needs an even number of parameters" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 379 379
122 379 my %params = @_;
123  
124 379 ▶ croak "wheels no longer require a kernel reference as their first parameter"
Branch: 1 branch
BranchTrueFalseTotal
if @_ and ref $_[0] eq "POE::Kernel" 0 379 379
Condition33%1/3
@_ and ref $_[0] eq "POE::Kernel"
!ll&&!rl&&r
03790
MC/DC0%0/2
@_ and ref $_[0] eq "POE::Kernel"
@_ ref $_[0] eq "POE::Kernel"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "POE::Kernel"
ABresult
0X0
100
111
125 if @_ and ref($_[0]) eq 'POE::Kernel';
126  
127 379 ▶ croak "$type requires a working Kernel" unless defined $poe_kernel;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $POE::Wheel::Run::poe_kernel 0 379 379
128  
129 379 my $program = delete $params{Program};
130 379 ▶ croak "$type needs a Program parameter" unless defined $program;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $program 16 363 379
131  
132 363 my $prog_args = delete $params{ProgramArgs};
133 363 ▶ $prog_args = [] unless defined $prog_args;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prog_args 260 103 363
134 363 ▶ croak "ProgramArgs must be an ARRAY reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $prog_args eq "ARRAY" 0 363 363
135 unless ref($prog_args) eq "ARRAY";
136  
137 363 my $priority_delta = delete $params{Priority};
138 363 ▶ $priority_delta = 0 unless defined $priority_delta;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $priority_delta 363 0 363
139  
140 363 my $close_on_call = delete $params{CloseOnCall};
141 363 ▶ $close_on_call = 0 unless defined $close_on_call;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $close_on_call 363 0 363
142  
143 363 my $user_id = delete $params{User};
144 363 my $group_id = delete $params{Group};
145  
146 # The following $stdio_type is new. $conduit is kept around for now
147 # to preserve the logic of the rest of the module. This change
148 # allows a Session using POE::Wheel::Run to define the type of pipe
149 # to be created for stdin and stdout. Read the POD on Conduit.
150 # However, the documentation lies, because if Conduit is undefined,
151 # $stdio_type is set to undefined (so the default pipe type provided
152 # by POE::Pipe::TwoWay will be used). Otherwise, $stdio_type
153 # determines what type of pipe Pipe:TwoWay creates unless it's
154 # 'pty'.
155  
156 363 my $conduit = delete $params{Conduit};
157 363 my $stdio_type;
158 363 ▶ if (defined $conduit) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $conduit) { } 72 291 363
159 72 ▶ croak "$type\'s Conduit type ($conduit) is unknown" if (
Branch: 1 branch
BranchTrueFalseTotal
if $conduit ne "pipe" and $conduit ne "pty" and $conduit ne "pty-pipe" and $conduit ne "socketpair" and $conduit ne "inet" 16 56 72
Condition100%12/12
$conduit ne "pipe" and $conduit ne "pty" and $conduit ne "pty-pipe" and $conduit ne "socketpair" and $conduit ne "inet"
!ll&&!rl&&r
54216
$conduit ne "pipe" and $conduit ne "pty" and $conduit ne "pty-pipe" and $conduit ne "socketpair"
!ll&&!rl&&r
52218
$conduit ne "pipe" and $conduit ne "pty" and $conduit ne "pty-pipe"
!ll&&!rl&&r
401220
$conduit ne "pipe" and $conduit ne "pty"
!ll&&!rl&&r
261432
MC/DC100%5/5
$conduit ne "pipe" and $conduit ne "pty" and $conduit ne "pty-pipe" and $conduit ne "socketpair" and $conduit ne "inet"
$conduit ne "pipe" $conduit ne "pty" $conduit ne "pty-pipe" $conduit ne "socketpair" $conduit ne "inet"
Truth table100%6/6
A and B and C and D and E
A= $conduit ne "pipe"B= $conduit ne "pty"C= $conduit ne "pty-pipe"D= $conduit ne "socketpair"E= $conduit ne "inet"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
160 $conduit ne 'pipe' and
161 $conduit ne 'pty' and
162 $conduit ne 'pty-pipe' and
163 $conduit ne 'socketpair' and
164 $conduit ne 'inet'
165 );
166 56 ▶ unless ($conduit =~ /^pty(-pipe)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conduit =~ /^pty(-pipe)?$/) 30 26 56
167 30 $stdio_type = $conduit;
168 30 $conduit = "pipe";
169 }
170 }
171 else {
172 291 $conduit = "pipe";
173 }
174  
175 347 my $winsize = delete $params{Winsize};
176  
177 347 ▶ if ($winsize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($winsize) 0 347 347
178 0 ▶ carp "winsize can only be specified for a Conduit of type pty"
Branch: 1 branch
BranchTrueFalseTotal
if not $conduit =~ /^pty(-pipe)?$/ and $winsize 0 0 0
Condition0%0/3
not $conduit =~ /^pty(-pipe)?$/ and $winsize
!ll&&!rl&&r
000
MC/DC0%0/2
not $conduit =~ /^pty(-pipe)?$/ and $winsize
not $conduit =~ /^pty(-pipe)?$/ $winsize
Truth table0%0/3
not(A) and B
A= not $conduit =~ /^pty(-pipe)?$/B= $winsize
ABresult
0X0
100
111
179 if $conduit !~ /^pty(-pipe)?$/ and $winsize;
180  
181 0 ▶ if( 'ARRAY' eq ref $winsize and 2==@$winsize ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("ARRAY" eq ref $winsize and 2 == @$winsize) 0 0 0
Condition0%0/3
"ARRAY" eq ref $winsize and 2 == @$winsize
!ll&&!rl&&r
000
MC/DC0%0/2
"ARRAY" eq ref $winsize and 2 == @$winsize
"ARRAY" eq ref $winsize 2 == @$winsize
Truth table0%0/3
A and B
A= "ARRAY" eq ref $winsizeB= 2 == @$winsize
ABresult
0X0
100
111
182 # Standard VGA cell in 9x16
183 # http://en.wikipedia.org/wiki/VGA-compatible_text_mode#Fonts
184 0 $winsize->[2] = $winsize->[1]*9;
185 0 $winsize->[3] = $winsize->[0]*16;
186 }
187 0 ▶ carp "winsize must be a 4 element arrayref" unless ref($winsize) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $winsize eq "ARRAY" and scalar @$winsize == 4 0 0 0
Condition0%0/3
ref $winsize eq "ARRAY" and scalar @$winsize == 4
!ll&&!rl&&r
000
MC/DC0%0/2
ref $winsize eq "ARRAY" and scalar @$winsize == 4
ref $winsize eq "ARRAY" scalar @$winsize == 4
Truth table0%0/3
A and B
A= ref $winsize eq "ARRAY"B= scalar @$winsize == 4
ABresult
0X0
100
111
188 and scalar @$winsize == 4;
189  
190 0 carp "winsize only works when IO::Tty::TIOCSWINSZ is"
191 unless TIOCSWINSZ_AVAILABLE;
192 }
193  
194 347 my $stdin_event = delete $params{StdinEvent};
195 347 my $stdout_event = delete $params{StdoutEvent};
196 347 my $stderr_event = delete $params{StderrEvent};
197  
198 347 ▶ if ($conduit eq 'pty' and defined $stderr_event) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conduit eq "pty" and defined $stderr_event) 0 347 347
Condition66%2/3
$conduit eq "pty" and defined $stderr_event
!ll&&!rl&&r
333140
MC/DC0%0/2
$conduit eq "pty" and defined $stderr_event
$conduit eq "pty" defined $stderr_event
Truth table66%2/3
A and B
A= $conduit eq "pty"B= defined $stderr_event
ABresult
0X0
100
111
199 0 carp "ignoring StderrEvent with pty conduit";
200 0 undef $stderr_event;
201 }
202  
203 #croak "$type needs at least one of StdinEvent, StdoutEvent or StderrEvent"
204 # unless (defined($stdin_event) or defined($stdout_event) or defined ($stderr_event));
205  
206 347 ▶ my $stdio_driver = delete $params{StdioDriver} || POE::Driver::SysRW->new();
Condition33%1/3
delete $params{'StdioDriver'} || 'POE::Driver::SysRW'->new
l!l&&r!l&&!r
03470
MC/DC0%0/2
delete $params{'StdioDriver'} || 'POE::Driver::SysRW'->new
delete $params{'StdioDriver'} 'POE::Driver::SysRW'->new
Truth table33%1/3
A || B
A= delete $params{'StdioDriver'}B= 'POE::Driver::SysRW'->new
ABresult
1X1
011
000
207 347 ▶ my $stdin_driver = delete $params{StdinDriver} || $stdio_driver;
Condition33%1/3
delete $params{'StdinDriver'} || $stdio_driver
l!l&&r!l&&!r
03470
MC/DC0%0/2
delete $params{'StdinDriver'} || $stdio_driver
delete $params{'StdinDriver'} $stdio_driver
Truth table33%1/3
A || B
A= delete $params{'StdinDriver'}B= $stdio_driver
ABresult
1X1
011
000
208 347 ▶ my $stdout_driver = delete $params{StdoutDriver} || $stdio_driver;
Condition33%1/3
delete $params{'StdoutDriver'} || $stdio_driver
l!l&&r!l&&!r
03470
MC/DC0%0/2
delete $params{'StdoutDriver'} || $stdio_driver
delete $params{'StdoutDriver'} $stdio_driver
Truth table33%1/3
A || B
A= delete $params{'StdoutDriver'}B= $stdio_driver
ABresult
1X1
011
000
209 347 ▶ my $stderr_driver = delete $params{StderrDriver} || POE::Driver::SysRW->new();
Condition33%1/3
delete $params{'StderrDriver'} || 'POE::Driver::SysRW'->new
l!l&&r!l&&!r
03470
MC/DC0%0/2
delete $params{'StderrDriver'} || 'POE::Driver::SysRW'->new
delete $params{'StderrDriver'} 'POE::Driver::SysRW'->new
Truth table33%1/3
A || B
A= delete $params{'StderrDriver'}B= 'POE::Driver::SysRW'->new
ABresult
1X1
011
000
210  
211 347 my $stdio_filter = delete $params{Filter};
212 347 my $stdin_filter = delete $params{StdinFilter};
213 347 my $stdout_filter = delete $params{StdoutFilter};
214 347 my $stderr_filter = delete $params{StderrFilter};
215  
216 #For optional redirection...
217 347 my $redir_err = delete $params{RedirectStderr};
218 347 my $redir_out = delete $params{RedirectStdout};
219 347 my $redir_in = delete $params{RedirectStdin};
220 347 my $redir_output = delete $params{RedirectOutput};
221  
222 347 my $no_stdin = delete $params{NoStdin};
223  
224 347 ▶ if(defined $redir_output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $redir_output) 4 343 347
225 4 $redir_out = $redir_err = $redir_output;
226 }
227  
228 #Sanity check. We can't wait for redirected filehandles
229 347 ▶ if( (defined $redir_in and defined $stdin_event) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $redir_in and defined $stdin_event or defined $redir_out and defined $stdout_event or defined $redir_err and defined $stderr_event) 16 331 347
Condition73%11/15
defined $redir_in and defined $stdin_event or defined $redir_out and defined $stdout_event or defined $redir_err and defined $stderr_event
l!l&&r!l&&!r
160331
defined $redir_in and defined $stdin_event or defined $redir_out and defined $stdout_event
l!l&&r!l&&!r
016331
defined $redir_in and defined $stdin_event
!ll&&!rl&&r
34340
defined $redir_out and defined $stdout_event
!ll&&!rl&&r
327416
defined $redir_err and defined $stderr_event
!ll&&!rl&&r
32740
MC/DC16%1/6
defined $redir_in and defined $stdin_event or defined $redir_out and defined $stdout_event or defined $redir_err and defined $stderr_event
defined $redir_in defined $stdin_event defined $redir_out defined $stdout_event defined $redir_err defined $stderr_event
Truth table20%3/15
A and B or C and D or E and F
A= defined $redir_inB= defined $stdin_eventC= defined $redir_outD= defined $stdout_eventE= defined $redir_errF= defined $stderr_event
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
230 (defined $redir_out and defined $stdout_event) ||
231 (defined $redir_err and defined $stderr_event) ) {
232 16 croak("Redirect* and *Event stdio options are mutually exclusive");
233 }
234  
235 331 ▶ if (defined $stdio_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdio_filter) { } 16 315 331
236 croak "Filter and StdioFilter cannot be used together"
237 16 ▶ if defined $params{StdioFilter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"StdioFilter"} 16 0 16
238 0 ▶ croak "Replace deprecated Filter with StdioFilter and StderrFilter"
Branch: 1 branch
BranchTrueFalseTotal
if defined $stderr_event and not defined $stderr_filter 0 0 0
Condition0%0/3
defined $stderr_event and not defined $stderr_filter
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stderr_event and not defined $stderr_filter
defined $stderr_event not defined $stderr_filter
Truth table0%0/3
A and not(B)
A= defined $stderr_eventB= not defined $stderr_filter
ABresult
0X0
100
111
239 if defined $stderr_event and not defined $stderr_filter;
240 0 carp "Filter is deprecated. Please try StdioFilter and/or StderrFilter";
241 }
242 else {
243 315 $stdio_filter = delete $params{StdioFilter};
244 }
245 315 ▶ $stdio_filter = POE::Filter::Line->new(Literal => "\n")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdio_filter 221 94 315
246 unless defined $stdio_filter;
247  
248 315 ▶ $stdin_filter = $stdio_filter unless defined $stdin_filter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdin_filter 225 90 315
249 315 ▶ $stdout_filter = $stdio_filter unless defined $stdout_filter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdout_filter 225 90 315
250  
251 315 ▶ if ($conduit eq 'pty' and defined $stderr_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conduit eq 'pty' and defined $stderr_filter) { } 0 315 315
Condition66%2/3
$conduit eq "pty" and defined $stderr_filter
!ll&&!rl&&r
301140
MC/DC0%0/2
$conduit eq "pty" and defined $stderr_filter
$conduit eq "pty" defined $stderr_filter
Truth table66%2/3
A and B
A= $conduit eq "pty"B= defined $stderr_filter
ABresult
0X0
100
111
252 0 carp "ignoring StderrFilter with pty conduit";
253 0 undef $stderr_filter;
254 }
255 else {
256 315 ▶ $stderr_filter = POE::Filter::Line->new(Literal => "\n")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stderr_filter 233 82 315
257 unless defined $stderr_filter;
258 }
259  
260 315 ▶ croak "$type needs either StdioFilter or StdinFilter when using StdinEvent"
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdin_event and not defined $stdin_filter 0 315 315
Condition66%2/3
defined $stdin_event and not defined $stdin_filter
!ll&&!rl&&r
1331820
MC/DC0%0/2
defined $stdin_event and not defined $stdin_filter
defined $stdin_event not defined $stdin_filter
Truth table66%2/3
A and not(B)
A= defined $stdin_eventB= not defined $stdin_filter
ABresult
0X0
100
111
261 if defined($stdin_event) and not defined($stdin_filter);
262 315 ▶ croak "$type needs either StdioFilter or StdoutFilter when using StdoutEvent"
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdout_event and not defined $stdout_filter 0 315 315
Condition66%2/3
defined $stdout_event and not defined $stdout_filter
!ll&&!rl&&r
103050
MC/DC0%0/2
defined $stdout_event and not defined $stdout_filter
defined $stdout_event not defined $stdout_filter
Truth table66%2/3
A and not(B)
A= defined $stdout_eventB= not defined $stdout_filter
ABresult
0X0
100
111
263 if defined($stdout_event) and not defined($stdout_filter);
264 315 ▶ croak "$type needs a StderrFilter when using StderrEvent"
Branch: 1 branch
BranchTrueFalseTotal
if defined $stderr_event and not defined $stderr_filter 0 315 315
Condition66%2/3
defined $stderr_event and not defined $stderr_filter
!ll&&!rl&&r
1112040
MC/DC0%0/2
defined $stderr_event and not defined $stderr_filter
defined $stderr_event not defined $stderr_filter
Truth table66%2/3
A and not(B)
A= defined $stderr_eventB= not defined $stderr_filter
ABresult
0X0
100
111
265 if defined($stderr_event) and not defined($stderr_filter);
266  
267 315 my $error_event = delete $params{ErrorEvent};
268 315 my $close_event = delete $params{CloseEvent};
269  
270 315 my $no_setsid = delete $params{NoSetSid};
271 315 my $no_setpgrp = delete $params{NoSetPgrp};
272  
273 # Make sure the user didn't pass in parameters we're not aware of.
274 315 ▶ if (scalar keys %params) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %params) 0 315 315
275 0 carp(
276 "unknown parameters in $type constructor call: ",
277 join(', ', sort keys %params)
278 );
279 }
280  
281 # Did the user mangle stdio?
282 315 ▶ unless (ref($program) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $program eq "CODE") 261 54 315
283 261 ▶ croak "Someone has closed or moved STDIN... exec() won't find it"
Branch: 1 branch
BranchTrueFalseTotal
unless defined fileno STDIN and fileno STDIN == 0 0 261 261
Condition33%1/3
defined fileno STDIN and fileno STDIN == 0
!ll&&!rl&&r
00261
MC/DC0%0/2
defined fileno STDIN and fileno STDIN == 0
defined fileno STDIN fileno STDIN == 0
Truth table33%1/3
A and B
A= defined fileno STDINB= fileno STDIN == 0
ABresult
0X0
100
111
284 unless defined fileno(STDIN) && fileno(STDIN) == 0;
285 261 ▶ croak "Someone has closed or moved STDOUT... exec() won't find it"
Branch: 1 branch
BranchTrueFalseTotal
unless tied *STDOUT or defined fileno STDOUT and fileno STDOUT == 1 0 261 261
Condition33%2/6
tied *STDOUT or defined fileno STDOUT and fileno STDOUT == 1
l!l&&r!l&&!r
02610
defined fileno STDOUT and fileno STDOUT == 1
!ll&&!rl&&r
00261
MC/DC0%0/3
tied *STDOUT or defined fileno STDOUT and fileno STDOUT == 1
tied *STDOUT defined fileno STDOUT fileno STDOUT == 1
Truth table25%1/4
A or B and C
A= tied *STDOUTB= defined fileno STDOUTC= fileno STDOUT == 1
ABCresult
1XX1
0111
00X0
0100
286 unless tied(*STDOUT) || defined fileno(STDOUT) && fileno(STDOUT) == 1;
287 261 ▶ croak "Someone has closed or moved STDERR... exec() won't find it"
Branch: 1 branch
BranchTrueFalseTotal
unless tied *STDERR or defined fileno STDERR and fileno STDERR == 2 0 261 261
Condition50%3/6
tied *STDERR or defined fileno STDERR and fileno STDERR == 2
l!l&&r!l&&!r
22590
defined fileno STDERR and fileno STDERR == 2
!ll&&!rl&&r
00259
MC/DC0%0/3
tied *STDERR or defined fileno STDERR and fileno STDERR == 2
tied *STDERR defined fileno STDERR fileno STDERR == 2
Truth table50%2/4
A or B and C
A= tied *STDERRB= defined fileno STDERRC= fileno STDERR == 2
ABCresult
1XX1
0111
00X0
0100
288 unless tied(*STDERR) || defined fileno(STDERR) && fileno(STDERR) == 2;
289 }
290  
291 my (
292 315 $stdin_read, $stdout_write, $stdout_read, $stdin_write,
293 $stderr_read, $stderr_write,
294 );
295  
296 315 _filespec_to_fh(\$stdin_read, "<", $redir_in);
297 315 ▶ if($redir_output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redir_output) { } 4 311 315
298 4 _filespec_to_fh(\$stdout_write, ">", $redir_output);
299 4 _filespec_to_fh(\$stderr_write, ">", $stdout_write);
300 } else {
301 311 _filespec_to_fh(\$stdout_write, ">", $redir_out);
302 311 _filespec_to_fh(\$stderr_write, ">", $redir_err);
303 }
304  
305 # Create a semaphore pipe. This is used so that the parent doesn't
306 # begin listening until the child's stdio has been set up.
307  
308 315 my ($sem_pipe_read, $sem_pipe_write) = POE::Pipe::OneWay->new();
309 315 ▶ croak "could not create semaphore pipe: $!" unless defined $sem_pipe_read;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sem_pipe_read 0 315 315
310  
311 # Use IO::Pty if requested. IO::Pty turns on autoflush for us.
312  
313 315 ▶ if(defined $stdout_event
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdout_event or defined $stdin_event or defined $stderr_event or not $no_stdin) 313 2 315
Condition88%8/9
defined $stdout_event or defined $stdin_event or defined $stderr_event or not $no_stdin
l!l&&r!l&&!r
30762
defined $stdout_event or defined $stdin_event or defined $stderr_event
l!l&&r!l&&!r
30528
defined $stdout_event or defined $stdin_event
l!l&&r!l&&!r
305010
MC/DC75%3/4
defined $stdout_event or defined $stdin_event or defined $stderr_event or not $no_stdin
defined $stdout_event defined $stdin_event defined $stderr_event not $no_stdin
Truth table80%4/5
A or B or C or not(D)
A= defined $stdout_eventB= defined $stdin_eventC= defined $stderr_eventD= not $no_stdin
ABCDresult
1XXX1
01XX1
001X1
00011
00000
314 or defined $stdin_event
315 or defined $stderr_event
316 or (!$no_stdin))
317 #Bypass all the conduit handling if the user does not care for child I/O
318 {
319 313 ▶ if ($conduit =~ /^pty(-pipe)?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($conduit =~ /^pty(-pipe)?$/) { } 26 287 313
elsif ($conduit eq 'pipe') { } 287 0 287
320 26 croak "IO::Pty is not available" unless PTY_AVAILABLE;
321  
322 26 ▶ if(defined $redir_err or defined $redir_in or defined $redir_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $redir_err or defined $redir_in or defined $redir_out) 0 26 26
Condition33%2/6
defined $redir_err or defined $redir_in or defined $redir_out
l!l&&r!l&&!r
0026
defined $redir_err or defined $redir_in
l!l&&r!l&&!r
0026
MC/DC0%0/3
defined $redir_err or defined $redir_in or defined $redir_out
defined $redir_err defined $redir_in defined $redir_out
Truth table25%1/4
A or B or C
A= defined $redir_errB= defined $redir_inC= defined $redir_out
ABCresult
1XX1
01X1
0011
0000
323 0 croak "Redirection with pty conduit is unsupported";
324 }
325  
326 26 $stdin_write = $stdout_read = IO::Pty->new();
327 26 ▶ croak "could not create master pty: $!" unless defined $stdout_read;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdout_read 0 26 26
328 26 ▶ if ($conduit eq "pty-pipe") {
Branch: 1 branch
BranchTrueFalseTotal
if ($conduit eq "pty-pipe") 12 14 26
329 12 ($stderr_read, $stderr_write) = POE::Pipe::OneWay->new();
330 12 ▶ croak "could not make stderr pipes: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stderr_read and defined $stderr_write 0 12 12
Condition33%1/3
defined $stderr_read and defined $stderr_write
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $stderr_read and defined $stderr_write
defined $stderr_read defined $stderr_write
Truth table33%1/3
A and B
A= defined $stderr_readB= defined $stderr_write
ABresult
0X0
100
111
331 unless defined $stderr_read and defined $stderr_write;
332 }
333 }
334  
335 # Use pipes otherwise.
336 elsif ($conduit eq 'pipe') {
337 # We make more pipes than strictly necessary in case someone wants
338 # to turn some on later. Uses a TwoWay pipe for STDIN/STDOUT and
339 # a OneWay pipe for STDERR. This may save 2 filehandles if
340 # socketpair() is available and no other $stdio_type is selected.
341  
342 287 foreach (
343 [\$redir_out, \$stdout_read, \$stdout_write, $stdout_event, "stdout"],
344 [\$redir_err, \$stderr_read, \$stderr_write, $stderr_event, "stderr"],
345 [\$redir_in, \$stdin_read, \$stdin_write, $stdin_event, "stdin"]
346 ) {
347 861 my ($redir_ref,$rfd_ref,$wfd_ref,$evname, $prettyprint) = @$_;
348 861 ▶ if(defined $evname && (!defined $$redir_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $evname and not defined $$redir_ref) 631 230 861
Condition66%2/3
defined $evname and not defined $$redir_ref
!ll&&!rl&&r
2300631
MC/DC50%1/2
defined $evname and not defined $$redir_ref
defined $evname not defined $$redir_ref
Truth table66%2/3
A and not(B)
A= defined $evnameB= not defined $$redir_ref
ABresult
0X0
100
111
349 631 ($$rfd_ref,$$wfd_ref) = POE::Pipe::OneWay->new();
350 631 ▶ croak "could not make $prettyprint pipe: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$rfd_ref and defined $$wfd_ref 0 631 631
Condition33%1/3
defined $$rfd_ref and defined $$wfd_ref
!ll&&!rl&&r
00631
MC/DC0%0/2
defined $$rfd_ref and defined $$wfd_ref
defined $$rfd_ref defined $$wfd_ref
Truth table33%1/3
A and B
A= defined $$rfd_refB= defined $$wfd_ref
ABresult
0X0
100
111
351 unless defined $$rfd_ref and defined $$wfd_ref;
352 }
353 }
354 287 ▶ unless (defined($redir_in) or $no_stdin) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $redir_in or $no_stdin) 283 4 287
Condition66%2/3
defined $redir_in or $no_stdin
l!l&&r!l&&!r
40283
MC/DC50%1/2
defined $redir_in or $no_stdin
defined $redir_in $no_stdin
Truth table66%2/3
A or B
A= defined $redir_inB= $no_stdin
ABresult
1X1
011
000
355 283 ($stdin_read, $stdin_write) = POE::Pipe::OneWay->new();
356 283 ▶ croak "could not make stdin pipe $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdin_write and defined $stdin_read 0 283 283
Condition33%1/3
defined $stdin_write and defined $stdin_read
!ll&&!rl&&r
00283
MC/DC0%0/2
defined $stdin_write and defined $stdin_read
defined $stdin_write defined $stdin_read
Truth table33%1/3
A and B
A= defined $stdin_writeB= defined $stdin_read
ABresult
0X0
100
111
357 unless defined $stdin_write and defined $stdin_read;
358 }
359 }
360  
361 # Sanity check.
362 else {
363 0 croak "unknown conduit type $conduit";
364 }
365 }
366  
367 # Block signals until safe
368 315 my $must_unmask;
369 315 ▶ if( $poe_kernel->can( '_data_sig_mask_all' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($POE::Wheel::Run::poe_kernel->can("_data_sig_mask_all")) 315 0 315
370 315 $poe_kernel->_data_sig_mask_all;
371 315 $must_unmask = 1;
372 }
373  
374 # Fork! Woo-hoo!
375 315 my $pid = fork;
376  
377 # Child. Parent side continues after this block.
378 315 ▶ unless ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 49 266 315
379 # removed the croak because it wasn't "safe" RT#56417
380 #croak "couldn't fork: $!" unless defined $pid;
381 # ANY OTHER DIE/CROAK/EXIT/WHATEVER in the child MUST use the helper!
382 49 ▶ __PACKAGE__->_warn_and_exit_child( "couldn't fork: $!", int( $! ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 49 49
383 unless defined $pid;
384  
385 # Stdio should not be tied. Resolves rt.cpan.org ticket 1648.
386 49 ▶ if (tied *STDIN) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied *STDIN) 0 49 49
387 0 carp "Cannot redirect out of tied STDIN. Untying it";
388 0 untie *STDIN;
389 }
390  
391 49 ▶ if (tied *STDOUT) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied *STDOUT) 0 49 49
392 0 carp "Cannot redirect into tied STDOUT. Untying it";
393 0 untie *STDOUT;
394 }
395  
396 49 ▶ if (tied *STDERR) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied *STDERR) 1 48 49
397 1 carp "Cannot redirect into tied STDERR. Untying it";
398 1 untie *STDERR;
399 }
400  
401 # If running pty, we delay the slave side creation 'til after
402 # doing the necessary bits to become our own [unix] session.
403 49 ▶ if ($conduit =~ /^pty(-pipe)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conduit =~ /^pty(-pipe)?$/) { } 4 45 49
404  
405 # Become a new unix session.
406 # Program 19.3, APITUE. W. Richard Stevens built my hot rod.
407 #eval 'setsid()' unless $no_setsid;
408  
409 # Acquire a controlling terminal. Program 19.3, APITUE.
410 4 $stdin_write->make_slave_controlling_terminal();
411  
412 # Open the slave side of the pty.
413 4 $stdin_read = $stdout_write = $stdin_write->slave();
414 4 ▶ __PACKAGE__->_warn_and_exit_child( "could not create slave pty: $!", int( $! ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdin_read 0 4 4
415 unless defined $stdin_read;
416  
417 # For a simple pty conduit, stderr is wedged into stdout.
418 4 ▶ $stderr_write = $stdout_write if $conduit eq 'pty';
Branch: 1 branch
BranchTrueFalseTotal
if $conduit eq "pty" 2 2 4
419  
420 # Put the pty conduit (slave side) into "raw" or "cbreak" mode,
421 # per APITUE 19.4 and 11.10.
422 4 $stdin_read->set_raw();
423  
424 4 if (TIOCSWINSZ_AVAILABLE) {
425 4 ▶ if ($winsize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($winsize) 0 4 4
426 0 ioctl($stdin_read, TIOCSWINSZ, pack('vvvv', @$winsize));
427 }
428 }
429 else {
430 # Set the pty conduit (slave side) window size to our window
431 # size. APITUE 19.4 and 19.5.
432  
433 eval { $stdin_read->clone_winsize_from(\*STDIN) } if -T STDIN;
434 }
435 }
436 else {
437 # TODO - Can this be block eval? Or a do{} block?
438 45 ▶ eval 'setpgrp(0,0)' unless $no_setpgrp;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_setpgrp 45 0 45
439 }
440  
441 # Reset all signals in the child process. POE's own handlers are
442 # silly to keep around in the child process since POE won't be
443 # using them.
444 49 my @safe_signals = $poe_kernel->_data_sig_get_safe_signals();
445 49 @SIG{@safe_signals} = ("DEFAULT") x @safe_signals;
446 49 ▶ $poe_kernel->_data_sig_unmask_all if $must_unmask;
Branch: 1 branch
BranchTrueFalseTotal
if $must_unmask 49 0 49
447  
448 # TODO How to pass events to the parent process? Maybe over a
449 # expedited (OOB) filehandle.
450  
451 # Fix the child process' priority. Don't bother doing this if it
452 # wasn't requested. Can't emit events on failure because we're in
453 # a separate process, so just fail quietly.
454  
455 49 ▶ if ($priority_delta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($priority_delta) 0 49 49
456 0 eval {
457 0 ▶ if (defined(my $priority = getpriority(0, $$))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $priority = getpriority(0, $$))) { } 0 0 0
458 0 ▶ unless (setpriority(0, $$, $priority + $priority_delta)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (setpriority 0, $$, $priority + $priority_delta) 0 0 0
459 # TODO can't set child priority
460 }
461 }
462 else {
463 # TODO can't get child priority
464 }
465 };
466 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
467 # TODO can't get child priority
468 }
469 }
470  
471 # Fix the group ID. TODO Add getgrnam so group IDs can be
472 # specified by name. TODO Warn if not superuser to begin with.
473 49 ▶ if (defined $group_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group_id) 0 49 49
474 0 $( = $) = $group_id;
475 }
476  
477 # Fix the user ID. TODO Add getpwnam so user IDs can be specified
478 # by name. TODO Warn if not superuser to begin with.
479 49 ▶ if (defined $user_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user_id) 0 49 49
480 0 $< = $> = $user_id;
481 }
482  
483 # Close what the child won't need.
484 49 ▶ close $stdin_write if defined $stdin_write;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdin_write 47 2 49
485 49 ▶ close $stdout_read if defined $stdout_read;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdout_read 46 3 49
486 49 ▶ close $stderr_read if defined $stderr_read;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stderr_read 29 20 49
487  
488 49 ▶ if (POE::Kernel::RUNNING_IN_HELL) {
Branch: 1 branch
BranchTrueFalseTotal
if (POE::Kernel::RUNNING_IN_HELL()) { } 0 49 49
489 0 __PACKAGE__->_redirect_child_stdio_in_hell(
490 $stdin_read, $stdout_write, $stderr_write
491 );
492 }
493  
494 else {
495 49 __PACKAGE__->_redirect_child_stdio_sanely(
496 $stdin_read, $stdout_write, $stderr_write
497 );
498 }
499  
500 # Make STDOUT and/or STDERR auto-flush.
501 49 select STDERR; $| = 1;
502 49 select STDOUT; $| = 1;
503  
504 # The child doesn't need to read from the semaphore pipe.
505 49 $sem_pipe_read = undef;
506  
507 # Run Perl code. This is fairly consistent across most systems.
508  
509 49 ▶ if (ref($program) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $program eq "CODE") 2 47 49
510  
511 # Tell the parent that the stdio has been set up.
512 2 print $sem_pipe_write "go\n";
513 2 close $sem_pipe_write;
514  
515 # Close any close-on-exec file descriptors. Except STDIN,
516 # STDOUT, and STDERR, of course.
517 2 ▶ if ($close_on_call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($close_on_call) 0 2 2
518 0 for (0..MAX_OPEN_FDS-1) {
519 0 ▶ next if fileno(STDIN) == $_;
Branch: 1 branch
BranchTrueFalseTotal
if fileno STDIN == $_ 0 0 0
520 0 ▶ next if fileno(STDOUT) == $_;
Branch: 1 branch
BranchTrueFalseTotal
if fileno STDOUT == $_ 0 0 0
521 0 ▶ next if fileno(STDERR) == $_;
Branch: 1 branch
BranchTrueFalseTotal
if fileno STDERR == $_ 0 0 0
522 0 POSIX::close($_);
523 }
524 }
525  
526 # TODO what if the program tries to exit? It needs to use
527 # our _exit_child_any_way_we_can handler...
528 # Should we replace CORE::exit? CORE::die too? blahhhhhh
529 # We've documented that users should not do it, but who knows!
530 2 eval { $program->(@$prog_args) };
531  
532 0 my $exitval;
533 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
534 0 chomp $@;
535 0 warn "$@\n";
536 0 $exitval = -1;
537 }
538  
539 0 ▶ __PACKAGE__->_exit_child_any_way_we_can( $exitval || 0 );
Condition0%0/2
$exitval || 0
l!l
00
MC/DC0%0/1
$exitval || 0
$exitval
Truth table0%0/2
A
A= $exitval
Aresult
11
00
540 }
541  
542 # Execute an external program. This gets weird.
543  
544 # Windows! What I do for you!
545 __PACKAGE__->_exec_in_hell(
546 47 ▶ $close_on_call, $sem_pipe_write, $program, $prog_args
Branch: 1 branch
BranchTrueFalseTotal
if POE::Kernel::RUNNING_IN_HELL() 0 47 47
547 ) if POE::Kernel::RUNNING_IN_HELL;
548  
549 # Everybody else seems sane.
550 # Tell the parent that the stdio has been set up.
551 47 print $sem_pipe_write "go\n";
552 47 close $sem_pipe_write;
553  
554 # exec(ARRAY)
555 47 ▶ if (ref($program) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $program eq "ARRAY") 47 0 47
556 47 ▶ exec(@$program, @$prog_args)
Branch: 1 branch
BranchTrueFalseTotal
exec @$program, @$prog_args or __PACKAGE__->_warn_and_exit_child("can't exec (@$program) in child pid ${$}: $!", int $!) 0 0 0
557 or __PACKAGE__->_warn_and_exit_child(
558 "can't exec (@$program) in child pid $$: $!", int( $! ) );
559 }
560  
561 # exec(SCALAR)
562 0 ▶ exec(join(" ", $program, @$prog_args))
Branch: 1 branch
BranchTrueFalseTotal
exec join(" ", $program, @$prog_args) or __PACKAGE__->_warn_and_exit_child("can't exec ($program) in child pid ${$}: $!", int $!) 0 0 0
563 or __PACKAGE__->_warn_and_exit_child(
564 "can't exec ($program) in child pid $$: $!", int( $! ) );
565 }
566  
567 # Parent here. Close what the parent won't need.
568  
569 266 ▶ defined($stdin_read) and close $stdin_read;
Branch: 1 branch
BranchTrueFalseTotal
defined $stdin_read and close $stdin_read 242 24 266
570 266 ▶ defined($stdout_write) and close $stdout_write;
Branch: 1 branch
BranchTrueFalseTotal
defined $stdout_write and close $stdout_write 239 27 266
571 266 ▶ defined($stderr_write) and close $stderr_write;
Branch: 1 branch
BranchTrueFalseTotal
defined $stderr_write and close $stderr_write 177 89 266
572  
573  
574  
575 # Also close any slave ptys
576 266 ▶ $stdout_read->close_slave() if (
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdout_read and ref $stdout_read eq "IO::Pty" 22 244 266
Condition100%3/3
defined $stdout_read and ref $stdout_read eq "IO::Pty"
!ll&&!rl&&r
723722
MC/DC100%2/2
defined $stdout_read and ref $stdout_read eq "IO::Pty"
defined $stdout_read ref $stdout_read eq "IO::Pty"
Truth table100%3/3
A and B
A= defined $stdout_readB= ref $stdout_read eq "IO::Pty"
ABresult
0X0
100
111
577 defined $stdout_read and ref($stdout_read) eq 'IO::Pty'
578 );
579  
580 266 ▶ $stderr_read->close_slave() if (
Branch: 1 branch
BranchTrueFalseTotal
if defined $stderr_read and ref $stderr_read eq "IO::Pty" 0 266 266
Condition66%2/3
defined $stderr_read and ref $stderr_read eq "IO::Pty"
!ll&&!rl&&r
911750
MC/DC0%0/2
defined $stderr_read and ref $stderr_read eq "IO::Pty"
defined $stderr_read ref $stderr_read eq "IO::Pty"
Truth table66%2/3
A and B
A= defined $stderr_readB= ref $stderr_read eq "IO::Pty"
ABresult
0X0
100
111
581 defined $stderr_read and ref($stderr_read) eq 'IO::Pty'
582 );
583  
584 266 my $active_count = 0;
585 266 ▶ $active_count++ if $stdout_event and $stdout_read;
Branch: 1 branch
BranchTrueFalseTotal
if $stdout_event and $stdout_read 259 7 266
Condition66%2/3
$stdout_event and $stdout_read
!ll&&!rl&&r
70259
MC/DC50%1/2
$stdout_event and $stdout_read
$stdout_event $stdout_read
Truth table66%2/3
A and B
A= $stdout_eventB= $stdout_read
ABresult
0X0
100
111
586 266 ▶ $active_count++ if $stderr_event and $stderr_read;
Branch: 1 branch
BranchTrueFalseTotal
if $stderr_event and $stderr_read 175 91 266
Condition66%2/3
$stderr_event and $stderr_read
!ll&&!rl&&r
910175
MC/DC50%1/2
$stderr_event and $stderr_read
$stderr_event $stderr_read
Truth table66%2/3
A and B
A= $stderr_eventB= $stderr_read
ABresult
0X0
100
111
587  
588 266 my $self = bless [
589 &POE::Wheel::allocate_wheel_id(), # UNIQUE_ID
590 $error_event, # ERROR_EVENT
591 $close_event, # CLOSE_EVENT
592 $program, # PROGRAM
593 $pid, # CHILD_PID
594 $conduit, # CONDUIT_TYPE
595 $active_count, # IS_ACTIVE
596 $close_on_call, # CLOSE_ON_CALL
597 $stdio_type, # STDIO_TYPE
598 # STDIN
599 $stdin_write, # HANDLE_STDIN
600 $stdin_filter, # FILTER_STDIN
601 $stdin_driver, # DRIVER_STDIN
602 $stdin_event, # EVENT_STDIN
603 undef, # STATE_STDIN
604 0, # OCTETS_STDIN
605 # STDOUT
606 $stdout_read, # HANDLE_STDOUT
607 $stdout_filter, # FILTER_STDOUT
608 $stdout_driver, # DRIVER_STDOUT
609 $stdout_event, # EVENT_STDOUT
610 undef, # STATE_STDOUT
611 # STDERR
612 $stderr_read, # HANDLE_STDERR
613 $stderr_filter, # FILTER_STDERR
614 $stderr_driver, # DRIVER_STDERR
615 $stderr_event, # EVENT_STDERR
616 undef, # STATE_STDERR
617 undef, # MSWIN32_GROUP_PID
618 ], $type;
619  
620 # PG- I suspect <> might need PIPE
621 266 ▶ $poe_kernel->_data_sig_unmask_all if $must_unmask;
Branch: 1 branch
BranchTrueFalseTotal
if $must_unmask 266 0 266
622  
623 # Wait here while the child sets itself up.
624 266 $sem_pipe_write = undef;
625 {
626 266 local $/ = "\n"; # TODO - Needed?
627 266 my $chldout = <$sem_pipe_read>;
628 266 chomp $chldout;
629 266 ▶ $self->[MSWIN32_GROUP_PID] = $chldout if $chldout ne 'go';
Branch: 1 branch
BranchTrueFalseTotal
if $chldout ne "go" 0 266 266
630 }
631 266 close $sem_pipe_read;
632  
633 266 ▶ $self->_define_stdin_flusher() if defined $stdin_write;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdin_write 262 4 266
634 266 ▶ $self->_define_stdout_reader() if defined $stdout_read;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdout_read 259 7 266
635 266 ▶ $self->_define_stderr_reader() if defined $stderr_read;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stderr_read 175 91 266
636  
637 266 return $self;
638 }
639  
640 #------------------------------------------------------------------------------
641 # Define the internal state that will flush output to the child
642 # process' STDIN pipe.
643  
644 262 ▶sub _define_stdin_flusher {
Subroutine _define_stdin_flusher: called CC=2 SCAR=7.2
645 262 my $self = shift;
646  
647 # Read-only members. If any of these change, then the write state
648 # is invalidated and needs to be redefined.
649 262 my $unique_id = $self->[UNIQUE_ID];
650 262 my $driver = $self->[DRIVER_STDIN];
651 262 my $error_event = \$self->[ERROR_EVENT];
652 262 my $close_event = \$self->[CLOSE_EVENT];
653 262 my $stdin_filter = $self->[FILTER_STDIN];
654 262 my $stdin_event = \$self->[EVENT_STDIN];
655 262 my $is_active = \$self->[IS_ACTIVE];
656  
657 # Read/write members. These are done by reference, to avoid pushing
658 # $self into the anonymous sub. Extra copies of $self are bad and
659 # can prevent wheels from destructing properly.
660 262 my $stdin_octets = \$self->[OCTETS_STDIN];
661  
662 # Register the select-write handler.
663 $poe_kernel->state(
664 $self->[STATE_STDIN] = ref($self) . "($unique_id) -> select stdin",
665 146 ▶ sub { # prevents SEGV
Subroutine __ANON__: called CC=5 SCAR=18.1
666 146 0 && CRIMSON_SCOPE_HACK('<');
667 # subroutine starts here
668 146 my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0];
669  
670 146 $$stdin_octets = $driver->flush($handle);
671  
672 # When you can't write, nothing else matters.
673 146 ▶ if ($!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!) { } 0 146 146
674 0 ▶ $$error_event && $k->call(
Branch: 1 branch
BranchTrueFalseTotal
$$error_event and $k->call($me, $$error_event, "write", $! + 0, $!, $unique_id, "STDIN") 0 0 0
675 $me, $$error_event,
676 'write', ($!+0), $!, $unique_id, "STDIN"
677 );
678 0 $k->select_write($handle);
679 }
680  
681 # Could write, or perhaps couldn't but only because the
682 # filehandle's buffer is choked.
683 else {
684  
685 # All chunks written; fire off a "flushed" event.
686 146 ▶ unless ($$stdin_octets) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$stdin_octets) 146 0 146
687 146 $k->select_pause_write($handle);
688 146 ▶ $$stdin_event && $k->call($me, $$stdin_event, $unique_id);
Branch: 1 branch
BranchTrueFalseTotal
$$stdin_event and $k->call($me, $$stdin_event, $unique_id) 66 80 146
689 }
690 }
691 }
692 262 );
693  
694 262 $poe_kernel->select_write($self->[HANDLE_STDIN], $self->[STATE_STDIN]);
695  
696 # Pause the write select immediately, unless output is pending.
697 262 ▶ $poe_kernel->select_pause_write($self->[HANDLE_STDIN])
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[14] 262 0 262
698 unless ($self->[OCTETS_STDIN]);
699 }
700  
701 #------------------------------------------------------------------------------
702 # Define the internal state that will read input from the child
703 # process' STDOUT pipe. This is virtually identical to
704 # _define_stderr_reader, but they aren't implemented as a common
705 # function for speed reasons.
706  
707 259 ▶sub _define_stdout_reader {
Subroutine _define_stdout_reader: called CC=5 SCAR=16.2
708 259 my $self = shift;
709  
710 # Can't do anything if we don't have a handle.
711 259 ▶ return unless defined $self->[HANDLE_STDOUT];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[15] 0 259 259
712  
713 # No event? Unregister the handler and leave.
714 259 my $stdout_event = \$self->[EVENT_STDOUT];
715 259 ▶ unless ($$stdout_event) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$stdout_event) 0 259 259
716 0 $poe_kernel->select_read($self->[HANDLE_STDOUT]);
717 0 return;
718 }
719  
720 # If any of these change, then the read state is invalidated and
721 # needs to be redefined.
722 259 my $unique_id = $self->[UNIQUE_ID];
723 259 my $driver = $self->[DRIVER_STDOUT];
724 259 my $stdout_filter = $self->[FILTER_STDOUT];
725  
726 # These can change without redefining the callback since they're
727 # enclosed by reference.
728 259 my $is_active = \$self->[IS_ACTIVE];
729 259 my $close_event = \$self->[CLOSE_EVENT];
730 259 my $error_event = \$self->[ERROR_EVENT];
731  
732 # Register the select-read handler for STDOUT.
733 259 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($stdout_filter->can('get_one') and $stdout_filter->can('get_one_start')) { } 223 36 259
Condition66%2/3
$stdout_filter->can("get_one") and $stdout_filter->can("get_one_start")
!ll&&!rl&&r
360223
MC/DC50%1/2
$stdout_filter->can("get_one") and $stdout_filter->can("get_one_start")
$stdout_filter->can("get_one") $stdout_filter->can("get_one_start")
Truth table66%2/3
A and B
A= $stdout_filter->can("get_one")B= $stdout_filter->can("get_one_start")
ABresult
0X0
100
111
734 $stdout_filter->can("get_one") and
735 $stdout_filter->can("get_one_start")
736 ) {
737 $poe_kernel->state(
738 $self->[STATE_STDOUT] = ref($self) . "($unique_id) -> select stdout",
739 242 ▶ sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
740 # prevents SEGV
741 242 0 && CRIMSON_SCOPE_HACK('<');
742  
743 # subroutine starts here
744 242 my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0];
745 242 ▶ if (defined(my $raw_input = $driver->get($handle))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raw_input = $driver->get($handle))) { } 58 184 242
746 58 $stdout_filter->get_one_start($raw_input);
747 58 while (1) {
748 115 my $next_rec = $stdout_filter->get_one();
749 115 ▶ last unless @$next_rec;
Branch: 1 branch
BranchTrueFalseTotal
unless @$next_rec 58 57 115
750 57 foreach my $cooked_input (@$next_rec) {
751 57 $k->call($me, $$stdout_event, $cooked_input, $unique_id);
752 }
753 }
754 }
755 else {
756 184 ▶ $$error_event and $k->call(
Branch: 1 branch
BranchTrueFalseTotal
$$error_event and $k->call($me, $$error_event, "read", $! + 0, $!, $unique_id, "STDOUT") 94 90 184
757 $me, $$error_event,
758 'read', ($!+0), $!, $unique_id, 'STDOUT'
759 );
760 184 ▶ unless (--$$is_active) {
Branch: 1 branch
BranchTrueFalseTotal
unless (--$$is_active) 139 45 184
761 139 ▶ $k->call( $me, $$close_event, $unique_id )
Branch: 1 branch
BranchTrueFalseTotal
if defined $$close_event 65 74 139
762 if defined $$close_event;
763 }
764 184 $k->select_read($handle);
765 }
766 }
767 223 );
768 }
769  
770 # Otherwise we can't get one.
771 else {
772 $poe_kernel->state(
773 $self->[STATE_STDOUT] = ref($self) . "($unique_id) -> select stdout",
774 26 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
775 # prevents SEGV
776 26 0 && CRIMSON_SCOPE_HACK('<');
777  
778 # subroutine starts here
779 26 my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0];
780 26 ▶ if (defined(my $raw_input = $driver->get($handle))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raw_input = $driver->get($handle))) { } 16 10 26
781 16 foreach my $cooked_input (@{$stdout_filter->get($raw_input)}) {
782 16 $k->call($me, $$stdout_event, $cooked_input, $unique_id);
783 }
784 }
785 else {
786 10 ▶ $$error_event and
Branch: 1 branch
BranchTrueFalseTotal
$$error_event and $k->call($me, $$error_event, "read", $! + 0, $!, $unique_id, "STDOUT") 10 0 10
787 $k->call(
788 $me, $$error_event,
789 'read', ($!+0), $!, $unique_id, 'STDOUT'
790 );
791 10 ▶ unless (--$$is_active) {
Branch: 1 branch
BranchTrueFalseTotal
unless (--$$is_active) 7 3 10
792 7 ▶ $k->call( $me, $$close_event, $unique_id )
Branch: 1 branch
BranchTrueFalseTotal
if defined $$close_event 7 0 7
793 if defined $$close_event;
794 }
795 10 $k->select_read($handle);
796 }
797 }
798 36 );
799 }
800  
801 # register the state's select
802 259 $poe_kernel->select_read($self->[HANDLE_STDOUT], $self->[STATE_STDOUT]);
803 }
804  
805 #------------------------------------------------------------------------------
806 # Define the internal state that will read input from the child
807 # process' STDERR pipe.
808  
809 175 ▶sub _define_stderr_reader {
Subroutine _define_stderr_reader: called CC=5 SCAR=16.2
810 175 my $self = shift;
811  
812 # Can't do anything if we don't have a handle.
813 175 ▶ return unless defined $self->[HANDLE_STDERR];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[20] 0 175 175
814  
815 # No event? Unregister the handler and leave.
816 175 my $stderr_event = \$self->[EVENT_STDERR];
817 175 ▶ unless ($$stderr_event) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$stderr_event) 0 175 175
818 0 $poe_kernel->select_read($self->[HANDLE_STDERR]);
819 0 return;
820 }
821  
822 175 my $unique_id = $self->[UNIQUE_ID];
823 175 my $driver = $self->[DRIVER_STDERR];
824 175 my $stderr_filter = $self->[FILTER_STDERR];
825  
826 # These can change without redefining the callback since they're
827 # enclosed by reference.
828 175 my $error_event = \$self->[ERROR_EVENT];
829 175 my $close_event = \$self->[CLOSE_EVENT];
830 175 my $is_active = \$self->[IS_ACTIVE];
831  
832 # Register the select-read handler for STDERR.
833 175 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($stderr_filter->can('get_one') and $stderr_filter->can('get_one_start')) { } 149 26 175
Condition66%2/3
$stderr_filter->can("get_one") and $stderr_filter->can("get_one_start")
!ll&&!rl&&r
260149
MC/DC50%1/2
$stderr_filter->can("get_one") and $stderr_filter->can("get_one_start")
$stderr_filter->can("get_one") $stderr_filter->can("get_one_start")
Truth table66%2/3
A and B
A= $stderr_filter->can("get_one")B= $stderr_filter->can("get_one_start")
ABresult
0X0
100
111
834 $stderr_filter->can("get_one") and
835 $stderr_filter->can("get_one_start")
836 ) {
837 $poe_kernel->state(
838 $self->[STATE_STDERR] = ref($self) . "($unique_id) -> select stderr",
839 125 ▶ sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
840 # prevents SEGV
841 125 0 && CRIMSON_SCOPE_HACK('<');
842  
843 # subroutine starts here
844 125 my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0];
845 125 ▶ if (defined(my $raw_input = $driver->get($handle))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raw_input = $driver->get($handle))) { } 16 109 125
846 16 $stderr_filter->get_one_start($raw_input);
847 16 while (1) {
848 32 my $next_rec = $stderr_filter->get_one();
849 32 ▶ last unless @$next_rec;
Branch: 1 branch
BranchTrueFalseTotal
unless @$next_rec 16 16 32
850 16 foreach my $cooked_input (@$next_rec) {
851 16 $k->call($me, $$stderr_event, $cooked_input, $unique_id);
852 }
853 }
854 }
855 else {
856 109 ▶ $$error_event and $k->call(
Branch: 1 branch
BranchTrueFalseTotal
$$error_event and $k->call($me, $$error_event, "read", $! + 0, $!, $unique_id, "STDERR") 94 15 109
857 $me, $$error_event,
858 'read', ($!+0), $!, $unique_id, 'STDERR'
859 );
860 109 ▶ unless (--$$is_active) {
Branch: 1 branch
BranchTrueFalseTotal
unless (--$$is_active) 45 64 109
861 45 ▶ $k->call( $me, $$close_event, $unique_id )
Branch: 1 branch
BranchTrueFalseTotal
if defined $$close_event 45 0 45
862 if defined $$close_event;
863 }
864 109 $k->select_read($handle);
865 }
866 }
867 149 );
868 }
869  
870 # Otherwise we can't get_one().
871 else {
872 $poe_kernel->state(
873 $self->[STATE_STDERR] = ref($self) . "($unique_id) -> select stderr",
874 10 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
875 # prevents SEGV
876 10 0 && CRIMSON_SCOPE_HACK('<');
877  
878 # subroutine starts here
879 10 my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0];
880 10 ▶ if (defined(my $raw_input = $driver->get($handle))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raw_input = $driver->get($handle))) { } 4 6 10
881 4 foreach my $cooked_input (@{$stderr_filter->get($raw_input)}) {
882 4 $k->call($me, $$stderr_event, $cooked_input, $unique_id);
883 }
884 }
885 else {
886 6 ▶ $$error_event and $k->call(
Branch: 1 branch
BranchTrueFalseTotal
$$error_event and $k->call($me, $$error_event, "read", $! + 0, $!, $unique_id, "STDERR") 6 0 6
887 $me, $$error_event,
888 'read', ($!+0), $!, $unique_id, 'STDERR'
889 );
890 6 ▶ unless (--$$is_active) {
Branch: 1 branch
BranchTrueFalseTotal
unless (--$$is_active) 3 3 6
891 3 ▶ $k->call( $me, $$close_event, $unique_id )
Branch: 1 branch
BranchTrueFalseTotal
if defined $$close_event 3 0 3
892 if defined $$close_event;
893 }
894 6 $k->select_read($handle);
895 }
896 }
897 26 );
898 }
899  
900 # Register the state's select.
901 175 $poe_kernel->select_read($self->[HANDLE_STDERR], $self->[STATE_STDERR]);
902 }
903  
904 #------------------------------------------------------------------------------
905 # Redefine events.
906  
907 164 ▶sub event {
Subroutine event: called CC=13 SCAR=26.5
Pod documented
908 164 my $self = shift;
909 164 ▶ push(@_, undef) if (scalar(@_) & 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ & 1 0 164 164
910  
911 164 my ($redefine_stdin, $redefine_stdout, $redefine_stderr) = (0, 0, 0);
912  
913 164 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 400 164 564
914 400 my ($name, $event) = splice(@_, 0, 2);
915  
916 400 ▶ if ($name eq 'StdinEvent') {
Branch: 5 branches
BranchTrueFalseTotal
if ($name eq 'StdinEvent') { } 82 318 400
elsif ($name eq 'StdoutEvent') { } 82 236 318
elsif ($name eq 'StderrEvent') { } 72 164 236
elsif ($name eq 'ErrorEvent') { } 82 82 164
elsif ($name eq 'CloseEvent') { } 82 0 82
917 82 $self->[EVENT_STDIN] = $event;
918 82 $redefine_stdin = 1;
919 }
920 elsif ($name eq 'StdoutEvent') {
921 82 $self->[EVENT_STDOUT] = $event;
922 82 $redefine_stdout = 1;
923 }
924 elsif ($name eq 'StderrEvent') {
925 72 ▶ if ($self->[CONDUIT_TYPE] ne 'pty') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[5] ne 'pty') { } 72 0 72
926 72 $self->[EVENT_STDERR] = $event;
927 72 $redefine_stderr = 1;
928 }
929 else {
930 0 carp "ignoring StderrEvent on a pty conduit";
931 }
932 }
933 elsif ($name eq 'ErrorEvent') {
934 82 $self->[ERROR_EVENT] = $event;
935 }
936 elsif ($name eq 'CloseEvent') {
937 82 $self->[CLOSE_EVENT] = $event;
938 }
939 else {
940 0 carp "ignoring unknown Run parameter '$name'";
941 }
942 }
943  
944 # Recalculate the active handles count.
945 164 my $active_count = 0;
946 164 ▶ $active_count++ if $self->[EVENT_STDOUT] and $self->[HANDLE_STDOUT];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[18] and $self->[15] 164 0 164
Condition33%1/3
$self->[18] and $self->[15]
!ll&&!rl&&r
00164
MC/DC0%0/2
$self->[18] and $self->[15]
$self->[18] $self->[15]
Truth table33%1/3
A and B
A= $self->[18]B= $self->[15]
ABresult
0X0
100
111
947 164 ▶ $active_count++ if $self->[EVENT_STDERR] and $self->[HANDLE_STDERR];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[23] and $self->[20] 144 20 164
Condition66%2/3
$self->[23] and $self->[20]
!ll&&!rl&&r
200144
MC/DC50%1/2
$self->[23] and $self->[20]
$self->[23] $self->[20]
Truth table66%2/3
A and B
A= $self->[23]B= $self->[20]
ABresult
0X0
100
111
948 164 $self->[IS_ACTIVE] = $active_count;
949 }
950  
951 #------------------------------------------------------------------------------
952 # Destroy the wheel.
953  
954 203 ▶sub DESTROY {
Subroutine DESTROY: called CC=8 SCAR=20.8
955 203 my $self = shift;
956  
957 203 ▶ return if(ref POE::Kernel->get_active_session eq 'POE::Kernel');
Branch: 1 branch
BranchTrueFalseTotal
if ref "POE::Kernel"->get_active_session eq "POE::Kernel" 2 201 203
958  
959 # Turn off the STDIN thing.
960 201 ▶ if ($self->[HANDLE_STDIN]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[9]) 197 4 201
961 197 $poe_kernel->select_write($self->[HANDLE_STDIN]);
962 197 $self->[HANDLE_STDIN] = undef;
963 }
964  
965 201 ▶ if ($self->[STATE_STDIN]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[13]) 199 2 201
966 199 $poe_kernel->state($self->[STATE_STDIN]);
967 199 $self->[STATE_STDIN] = undef;
968 }
969  
970 201 ▶ if ($self->[HANDLE_STDOUT]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[15]) 196 5 201
971 196 $poe_kernel->select_read($self->[HANDLE_STDOUT]);
972 196 $self->[HANDLE_STDOUT] = undef;
973 }
974 201 ▶ if ($self->[STATE_STDOUT]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[19]) 196 5 201
975 196 $poe_kernel->state($self->[STATE_STDOUT]);
976 196 $self->[STATE_STDOUT] = undef;
977 }
978  
979 201 ▶ if ($self->[HANDLE_STDERR]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[20]) 118 83 201
980 118 $poe_kernel->select_read($self->[HANDLE_STDERR]);
981 118 $self->[HANDLE_STDERR] = undef;
982 }
983 201 ▶ if ($self->[STATE_STDERR]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[24]) 118 83 201
984 118 $poe_kernel->state($self->[STATE_STDERR]);
985 118 $self->[STATE_STDERR] = undef;
986 }
987  
988 201 &POE::Wheel::free_wheel_id($self->[UNIQUE_ID]);
989 }
990  
991 #------------------------------------------------------------------------------
992 # Queue input for the child process.
993  
994 224 ▶sub put {
Subroutine put: called CC=3 SCAR=11.0
Pod documented
995 224 my ($self, @chunks) = @_;
996  
997 # Avoid big bada boom if someone put()s on a dead wheel.
998 224 ▶ croak "Called put() on a wheel without an open STDIN handle" unless (
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[9] 2 222 224
999 $self->[HANDLE_STDIN]
1000 );
1001  
1002 222 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[14] = $self->[11]->put($self->[10]->put(\@chunks))) 222 0 222
1003 $self->[OCTETS_STDIN] = # assignment on purpose
1004 $self->[DRIVER_STDIN]->put($self->[FILTER_STDIN]->put(\@chunks))
1005 ) {
1006 222 $poe_kernel->select_resume_write($self->[HANDLE_STDIN]);
1007 }
1008  
1009 # No watermark.
1010 222 return 0;
1011 }
1012  
1013 #------------------------------------------------------------------------------
1014 # Pause and resume various input events.
1015  
1016 2 ▶sub pause_stdout {
Subroutine pause_stdout: called CC=2 SCAR=7.1
Pod documented
1017 2 my $self = shift;
1018 2 ▶ return unless defined $self->[HANDLE_STDOUT];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[15] 0 2 2
1019 2 $poe_kernel->select_pause_read($self->[HANDLE_STDOUT]);
1020 }
1021  
1022 2 ▶sub pause_stderr {
Subroutine pause_stderr: called CC=2 SCAR=7.1
Pod documented
1023 2 my $self = shift;
1024 2 ▶ return unless defined $self->[HANDLE_STDERR];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[20] 0 2 2
1025 2 $poe_kernel->select_pause_read($self->[HANDLE_STDERR]);
1026 }
1027  
1028 2 ▶sub resume_stdout {
Subroutine resume_stdout: called CC=2 SCAR=7.1
Pod documented
1029 2 my $self = shift;
1030 2 ▶ return unless defined $self->[HANDLE_STDOUT];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[15] 0 2 2
1031 2 $poe_kernel->select_resume_read($self->[HANDLE_STDOUT]);
1032 }
1033  
1034 2 ▶sub resume_stderr {
Subroutine resume_stderr: called CC=2 SCAR=7.1
Pod documented
1035 2 my $self = shift;
1036 2 ▶ return unless defined $self->[HANDLE_STDERR];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[20] 0 2 2
1037 2 $poe_kernel->select_resume_read($self->[HANDLE_STDERR]);
1038 }
1039  
1040 # Shutdown the pipe that leads to the child's STDIN.
1041 2 ▶sub shutdown_stdin {
Subroutine shutdown_stdin: called CC=4 SCAR=14.5
Pod documented
1042 2 my $self = shift;
1043 2 ▶ return unless defined $self->[HANDLE_STDIN];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[9] 0 2 2
1044  
1045 2 $poe_kernel->select_write($self->[HANDLE_STDIN], undef);
1046  
1047 2 eval { local $^W = 0; shutdown($self->[HANDLE_STDIN], 1) };
1048 2 ▶ if ($@ or $self->[HANDLE_STDIN] != $self->[HANDLE_STDOUT]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or $self->[9] != $self->[15]) 2 0 2
Condition33%1/3
$@ or $self->[9] != $self->[15]
l!l&&r!l&&!r
020
MC/DC0%0/2
$@ or $self->[9] != $self->[15]
$@ $self->[9] != $self->[15]
Truth table33%1/3
A or B
A= $@B= $self->[9] != $self->[15]
ABresult
1X1
011
000
1049 2 close $self->[HANDLE_STDIN];
1050 }
1051  
1052 2 $self->[HANDLE_STDIN] = undef;
1053 }
1054  
1055 #------------------------------------------------------------------------------
1056 # Redefine filters, one at a time or at once. This is based on PG's
1057 # code in Wheel::ReadWrite.
1058  
1059 0 ▶sub _transfer_stdout_buffer {
Subroutine _transfer_stdout_buffer: not called CC=8 SCAR=42.8
1060 0 my ($self, $buf) = @_;
1061  
1062 0 my $old_output_filter = $self->[FILTER_STDOUT];
1063  
1064 # Assign old buffer contents to the new filter, and send out any
1065 # pending packets.
1066  
1067 # Use "get_one" if the new filter implements it.
1068 0 ▶ if (defined $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf) 0 0 0
1069 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($old_output_filter->can('get_one') and $old_output_filter->can('get_one_start')) { } 0 0 0
Condition0%0/3
$old_output_filter->can("get_one") and $old_output_filter->can("get_one_start")
!ll&&!rl&&r
000
MC/DC0%0/2
$old_output_filter->can("get_one") and $old_output_filter->can("get_one_start")
$old_output_filter->can("get_one") $old_output_filter->can("get_one_start")
Truth table0%0/3
A and B
A= $old_output_filter->can("get_one")B= $old_output_filter->can("get_one_start")
ABresult
0X0
100
111
1070 $old_output_filter->can("get_one") and
1071 $old_output_filter->can("get_one_start")
1072 ) {
1073 0 $old_output_filter->get_one_start($buf);
1074  
1075 # Don't bother to continue if the filter has switched out from
1076 # under our feet again. The new switcher will finish the job.
1077  
1078 0 ▶ while ($self->[FILTER_STDOUT] == $old_output_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[16] == $old_output_filter) 0 0 0
1079 0 my $next_rec = $old_output_filter->get_one();
1080 0 ▶ last unless @$next_rec;
Branch: 1 branch
BranchTrueFalseTotal
unless @$next_rec 0 0 0
1081 0 foreach my $cooked_input (@$next_rec) {
1082 0 $poe_kernel->call(
1083 $poe_kernel->get_active_session(), $self->[EVENT_STDOUT],
1084 $cooked_input, $self->[UNIQUE_ID]
1085 );
1086 }
1087 }
1088 }
1089  
1090 # Otherwise use the old get() behavior.
1091 else {
1092 0 foreach my $cooked_input (@{$self->[FILTER_STDOUT]->get($buf)}) {
1093 0 $poe_kernel->call(
1094 $poe_kernel->get_active_session(), $self->[EVENT_STDOUT],
1095 $cooked_input, $self->[UNIQUE_ID]
1096 );
1097 }
1098 }
1099 }
1100 }
1101  
1102 0 ▶sub _transfer_stderr_buffer {
Subroutine _transfer_stderr_buffer: not called CC=8 SCAR=42.8
1103 0 my ($self, $buf) = @_;
1104  
1105 0 my $old_output_filter = $self->[FILTER_STDERR];
1106  
1107 # Assign old buffer contents to the new filter, and send out any
1108 # pending packets.
1109  
1110 # Use "get_one" if the new filter implements it.
1111 0 ▶ if (defined $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf) 0 0 0
1112 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($old_output_filter->can('get_one') and $old_output_filter->can('get_one_start')) { } 0 0 0
Condition0%0/3
$old_output_filter->can("get_one") and $old_output_filter->can("get_one_start")
!ll&&!rl&&r
000
MC/DC0%0/2
$old_output_filter->can("get_one") and $old_output_filter->can("get_one_start")
$old_output_filter->can("get_one") $old_output_filter->can("get_one_start")
Truth table0%0/3
A and B
A= $old_output_filter->can("get_one")B= $old_output_filter->can("get_one_start")
ABresult
0X0
100
111
1113 $old_output_filter->can("get_one") and
1114 $old_output_filter->can("get_one_start")
1115 ) {
1116 0 $old_output_filter->get_one_start($buf);
1117  
1118 # Don't bother to continue if the filter has switched out from
1119 # under our feet again. The new switcher will finish the job.
1120  
1121 0 ▶ while ($self->[FILTER_STDERR] == $old_output_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[21] == $old_output_filter) 0 0 0
1122 0 my $next_rec = $old_output_filter->get_one();
1123 0 ▶ last unless @$next_rec;
Branch: 1 branch
BranchTrueFalseTotal
unless @$next_rec 0 0 0
1124 0 foreach my $cooked_input (@$next_rec) {
1125 0 $poe_kernel->call(
1126 $poe_kernel->get_active_session(), $self->[EVENT_STDERR],
1127 $cooked_input, $self->[UNIQUE_ID]
1128 );
1129 }
1130 }
1131 }
1132  
1133 # Otherwise use the old get() behavior.
1134 else {
1135 0 foreach my $cooked_input (@{$self->[FILTER_STDERR]->get($buf)}) {
1136 0 $poe_kernel->call(
1137 $poe_kernel->get_active_session(), $self->[EVENT_STDERR],
1138 $cooked_input, $self->[UNIQUE_ID]
1139 );
1140 }
1141 }
1142 }
1143 }
1144  
1145 0 ▶sub set_stdio_filter {
Subroutine set_stdio_filter: not called CC=1 SCAR=6.9
Pod documented
1146 0 my ($self, $new_filter) = @_;
1147 0 $self->set_stdout_filter($new_filter);
1148 0 $self->set_stdin_filter($new_filter);
1149 }
1150  
1151 0 ▶sub set_stdin_filter {
Subroutine set_stdin_filter: not called CC=1 SCAR=6.9
Pod documented
1152 0 my ($self, $new_filter) = @_;
1153 0 $self->[FILTER_STDIN] = $new_filter;
1154 }
1155  
1156 0 ▶sub set_stdout_filter {
Subroutine set_stdout_filter: not called CC=1 SCAR=6.9
Pod documented
1157 0 my ($self, $new_filter) = @_;
1158  
1159 0 my $buf = $self->[FILTER_STDOUT]->get_pending();
1160 0 $self->[FILTER_STDOUT] = $new_filter;
1161  
1162 0 $self->_transfer_stdout_buffer($buf);
1163 }
1164  
1165 0 ▶sub set_stderr_filter {
Subroutine set_stderr_filter: not called CC=1 SCAR=6.9
Pod documented
1166 0 my ($self, $new_filter) = @_;
1167  
1168 0 my $buf = $self->[FILTER_STDERR]->get_pending();
1169 0 $self->[FILTER_STDERR] = $new_filter;
1170  
1171 0 $self->_transfer_stderr_buffer($buf);
1172 }
1173  
1174 0 ▶sub get_stdin_filter {
Subroutine get_stdin_filter: not called CC=1 SCAR=6.9
Pod documented
1175 0 my $self = shift;
1176 0 return $self->[FILTER_STDIN];
1177 }
1178  
1179 0 ▶sub get_stdout_filter {
Subroutine get_stdout_filter: not called CC=1 SCAR=6.9
Pod documented
1180 0 my $self = shift;
1181 0 return $self->[FILTER_STDOUT];
1182 }
1183  
1184 0 ▶sub get_stderr_filter {
Subroutine get_stderr_filter: not called CC=1 SCAR=6.9
Pod documented
1185 0 my $self = shift;
1186 0 return $self->[FILTER_STDERR];
1187 }
1188  
1189 #------------------------------------------------------------------------------
1190 # Data accessors.
1191  
1192 20 ▶sub get_driver_out_octets {
Subroutine get_driver_out_octets: called CC=1 SCAR=0.0
Pod documented
1193 20 $_[0]->[OCTETS_STDIN];
1194 }
1195  
1196 20 ▶sub get_driver_out_messages {
Subroutine get_driver_out_messages: called CC=1 SCAR=0.0
Pod documented
1197 20 $_[0]->[DRIVER_STDIN]->get_out_messages_buffered();
1198 }
1199  
1200 170 ▶sub ID {
Subroutine ID: called CC=1 SCAR=0.0
Pod documented
1201 170 $_[0]->[UNIQUE_ID];
1202 }
1203  
1204 311 ▶sub PID {
Subroutine PID: called CC=1 SCAR=0.0
Pod documented
1205 311 $_[0]->[CHILD_PID];
1206 }
1207  
1208 4 ▶sub kill {
Subroutine kill: called CC=4 SCAR=16.4
Pod documented
1209 4 my ($self, $signal) = @_;
1210 4 ▶ $signal = 'TERM' unless defined $signal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $signal 4 0 4
1211 4 ▶ if ( $self->[MSWIN32_GROUP_PID] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[25]) { } 0 4 4
1212 # TODO use https://rt.cpan.org/Ticket/Display.html?id=67774 when available :)
1213 0 ▶ Win32::Process::KillProcess( $self->[MSWIN32_GROUP_PID], 293 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
Win32::Process::KillProcess($self->[25], 293) ? : 0 0 0
1214 }
1215 else {
1216 4 eval { kill $signal, $self->[CHILD_PID] };
1217 }
1218 }
1219  
1220 ### Internal helpers.
1221  
1222 0 ▶sub _redirect_child_stdio_in_hell {
Subroutine _redirect_child_stdio_in_hell: not called CC=4 SCAR=30.0
1223 0 my ($class, $stdin_read, $stdout_write, $stderr_write) = @_;
1224  
1225 # Win32 needs the stdio handles closed before they're reopened
1226 # because the standard handles aren't dup()'d.
1227  
1228 0 close STDIN;
1229 0 close STDOUT;
1230 0 close STDERR;
1231  
1232 0 $class->_redirect_child_stdio_sanely(
1233 $stdin_read, $stdout_write, $stderr_write
1234 );
1235  
1236 # The Win32 pseudo fork sets up the std handles in the child
1237 # based on the true win32 handles. The reopening of stdio
1238 # handles isn't enough. We must also set the underlying
1239 # Win32 notion of these handles for completeness.
1240 #
1241 # Only necessary for the exec, as Perl CODE subroutine goes
1242 # through 0/1/2 which are correct. But of course that coderef
1243 # might invoke exec, so better do it regardless.
1244 #
1245 # HACK: Using Win32::Console as nothing else exposes
1246 # SetStdHandle
1247 #
1248 # TODO - https://rt.cpan.org/Ticket/Display.html?id=50068 claims
1249 # that these _SetStdHandle() calls may leak memory. Do we have
1250 # alternatives?
1251  
1252 0 ▶ Win32::Console::_SetStdHandle(
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdin_read 0 0 0
1253 $STD_INPUT_HANDLE,
1254 FdGetOsFHandle(fileno($stdin_read))
1255 ) if defined $stdin_read;
1256  
1257 0 ▶ Win32::Console::_SetStdHandle(
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdout_write 0 0 0
1258 $STD_OUTPUT_HANDLE,
1259 FdGetOsFHandle(fileno($stdout_write))
1260 ) if defined $stdout_write;
1261  
1262 0 ▶ Win32::Console::_SetStdHandle(
Branch: 1 branch
BranchTrueFalseTotal
if defined $stderr_write 0 0 0
1263 $STD_ERROR_HANDLE,
1264 FdGetOsFHandle(fileno($stderr_write))
1265 ) if defined $stderr_write;
1266 }
1267  
1268 945 ▶sub _filespec_to_fh {
Subroutine _filespec_to_fh: called CC=4 SCAR=15.0
1269 945 my ($dest,$mode,$fspec) = @_;
1270 945 ▶ return unless defined $fspec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fspec 933 12 945
1271 12 ▶ if(ref $fspec) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fspec) { } 12 0 12
1272 12 ▶ if (ref $fspec eq 'GLOB') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fspec eq 'GLOB') { } 12 0 12
1273 12 open $$dest, "$mode&", $fspec;
1274 } else {
1275 0 die("Bad file specifier '$fspec'");
1276 }
1277 } else {
1278 0 open $$dest, $mode, $fspec;
1279 }
1280 }
1281  
1282 49 ▶sub _redirect_child_stdio_sanely {
Subroutine _redirect_child_stdio_sanely: called CC=7 SCAR=20.1
1283 49 my ($class, $stdin_read, $stdout_write, $stderr_write) = @_;
1284  
1285 # Note: we use 2-arg open() below because Perl 5.6 doesn't recognize
1286 # the '>&' and '<&' modes with a 3-arg open()
1287  
1288 # Redirect STDIN from the read end of the stdin pipe.
1289 49 ▶ if(defined $stdin_read) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdin_read) 49 0 49
1290 49 ▶ open( STDIN, "<&" . fileno($stdin_read) )
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, '<&' . fileno($stdin_read) or $class->_warn_and_exit_child("can't redirect STDIN in child pid ${$}: $!", int $!) 49 0 49
1291 or $class->_warn_and_exit_child(
1292 "can't redirect STDIN in child pid $$: $!", int( $! ) );
1293 }
1294  
1295 # Redirect STDOUT to the write end of the stdout pipe.
1296 49 ▶ if(defined $stdout_write) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdout_write) 48 1 49
1297 48 ▶ open( STDOUT, ">&" . fileno($stdout_write) )
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, '>&' . fileno($stdout_write) or $class->_warn_and_exit_child("can't redirect stdout in child pid ${$}: $!", int $!) 48 0 48
1298 or $class->_warn_and_exit_child(
1299 "can't redirect stdout in child pid $$: $!", int( $! ) );
1300 }
1301 # Redirect STDERR to the write end of the stderr pipe.
1302 49 ▶ if(defined $stderr_write) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stderr_write) 33 16 49
1303 33 ▶ open( STDERR, ">&" . fileno($stderr_write) )
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, '>&' . fileno($stderr_write) or $class->_warn_and_exit_child("can't redirect stderr in child pid ${$}: $!", int $!) 33 0 33
1304 or $class->_warn_and_exit_child(
1305 "can't redirect stderr in child pid $$: $!", int( $! ) );
1306 }
1307 }
1308  
1309 0 ▶sub _exit_child_any_way_we_can {
Subroutine _exit_child_any_way_we_can: not called CC=6 SCAR=37.4
1310 0 my $class = shift;
1311 0 ▶ my $exitval = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1312  
1313 # First make sure stdio are flushed.
1314 0 ▶ close STDIN if defined fileno(STDIN); # Voodoo?
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDIN 0 0 0
1315 0 ▶ close STDOUT if defined fileno(STDOUT);
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDOUT 0 0 0
1316 0 ▶ close STDERR if defined fileno(STDERR);
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDERR 0 0 0
1317  
1318 # On Windows, subprocesses run in separate threads. All the "fancy"
1319 # methods act on entire processes, so they also exit the parent.
1320  
1321 0 ▶ unless (POE::Kernel::RUNNING_IN_HELL) {
Branch: 1 branch
BranchTrueFalseTotal
if (POE::Kernel::RUNNING_IN_HELL()) { } 0 0 0
1322 # Try to avoid triggering END blocks and object destructors.
1323 0 eval { POSIX::_exit( $exitval ); };
1324  
1325 # TODO those methods will not exit with $exitval... what to do?
1326 0 eval { CORE::kill KILL => $$; };
1327 0 eval { exec("$^X -e 0"); };
1328 } else {
1329 0 eval { CORE::kill( KILL => $$ ); };
1330  
1331 # TODO Interestingly enough, the KILL is not enough to terminate this process...
1332 # However, it *is* enough to stop execution of END blocks/etc
1333 # So we will end up falling through to the exit( $exitval ) below
1334 }
1335  
1336 # Do what we must.
1337 0 exit( $exitval );
1338 }
1339  
1340 # RUNNING_IN_HELL use Win32::Process to create a pucker new shiny
1341 # process. It'll inherit our processes handles which is neat.
1342  
1343 0 ▶sub _exec_in_hell {
Subroutine _exec_in_hell: not called CC=15 SCAR=54.8
1344 my (
1345 0 $class, $close_on_call, $sem_pipe_write,
1346 $program, $prog_args
1347 ) = @_;
1348  
1349 # Close any close-on-exec file descriptors.
1350 # Except STDIN, STDOUT, and STDERR, of course.
1351  
1352 0 ▶ if ($close_on_call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($close_on_call) 0 0 0
1353 0 for (0..MAX_OPEN_FDS-1) {
1354 0 ▶ next if fileno(STDIN) == $_;
Branch: 1 branch
BranchTrueFalseTotal
if fileno STDIN == $_ 0 0 0
1355 0 ▶ next if fileno(STDOUT) == $_;
Branch: 1 branch
BranchTrueFalseTotal
if fileno STDOUT == $_ 0 0 0
1356 0 ▶ next if fileno(STDERR) == $_;
Branch: 1 branch
BranchTrueFalseTotal
if fileno STDERR == $_ 0 0 0
1357 0 POSIX::close($_);
1358 }
1359 }
1360  
1361 0 my ($appname, $cmdline);
1362  
1363 0 ▶ if (ref $program eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $program eq 'ARRAY') { } 0 0 0
1364 0 $appname = $program->[0];
1365 $cmdline = join(
1366 ' ',
1367 0 ▶ map { /\s/ && ! /"/ ? qq{"$_"} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
/\s/ && !/"/ ? : 0 0 0
Condition0%0/3
/\s/ and not /"/
!ll&&!rl&&r
000
MC/DC0%0/2
/\s/ and not /"/
/\s/ not /"/
Truth table0%0/3
A and not(B)
A= /\s/B= not /"/
ABresult
0X0
100
111
1368 (@$program, @$prog_args)
1369 );
1370 }
1371 else {
1372 0 $appname = undef;
1373 $cmdline = join(
1374 ' ', $program,
1375 0 ▶ map { /\s/ && ! /"/ ? qq{"$_"} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
/\s/ && !/"/ ? : 0 0 0
Condition0%0/3
/\s/ and not /"/
!ll&&!rl&&r
000
MC/DC0%0/2
/\s/ and not /"/
/\s/ not /"/
Truth table0%0/3
A and not(B)
A= /\s/B= not /"/
ABresult
0X0
100
111
1376 @$prog_args
1377 );
1378 }
1379  
1380 0 my $w32job;
1381  
1382 0 ▶ unless ( $w32job = Win32::Job->new() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($w32job = "Win32::Job"->new) 0 0 0
1383 0 print $sem_pipe_write "go\n\n"; # TODO why the double newline?
1384 0 close $sem_pipe_write;
1385 0 $class->_warn_and_exit_child(
1386 Win32::FormatMessage( Win32::GetLastError() ), Win32::GetLastError() );
1387 }
1388  
1389 0 my $w32pid;
1390  
1391 0 ▶ unless ( $w32pid = $w32job->spawn( $appname, $cmdline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($w32pid = $w32job->spawn($appname, $cmdline)) 0 0 0
1392 0 print $sem_pipe_write "go\n";
1393 0 close $sem_pipe_write;
1394 0 $class->_warn_and_exit_child(
1395 Win32::FormatMessage( Win32::GetLastError() ), Win32::GetLastError() );
1396 }
1397  
1398 0 print $sem_pipe_write "$w32pid\n";
1399 0 close $sem_pipe_write;
1400  
1401 # TODO why 60? Why not MAX_INT so we don't do unnecessary work?
1402 0 ▶ my $ok = $w32job->watch( sub { 0 }, 60 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1403 0 my $hashref = $w32job->status();
1404  
1405 # In case flushing them wasn't good enough.
1406 0 ▶ close STDOUT if defined fileno(STDOUT);
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDOUT 0 0 0
1407 0 ▶ close STDERR if defined fileno(STDERR);
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDERR 0 0 0
1408  
1409 0 $class->_exit_child_any_way_we_can( $hashref->{$w32pid}->{exitcode} );
1410 }
1411  
1412 # Simple helper to ease the pain of warn+exit
1413 0 ▶sub _warn_and_exit_child {
Subroutine _warn_and_exit_child: not called CC=1 SCAR=6.9
1414 0 my( $class, $warning, $exitval ) = @_;
1415  
1416 0 warn "$warning\n";
1417  
1418 0 $class->_exit_child_any_way_we_can( $exitval );
1419 }
1420  
1421 73 1;
1422  
1423 __END__
« blib/lib/POE/Wheel/SocketFactory.pm ↑ Summary blib/lib/POE/Wheel/FollowTail.pm »