line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TAP::Parser::Iterator::Process; |
2
|
|
|
|
|
|
|
|
3
|
62
|
|
|
62
|
|
18508
|
use strict; |
|
62
|
|
|
|
|
112
|
|
|
62
|
|
|
|
|
2063
|
|
4
|
62
|
|
|
62
|
|
269
|
use warnings; |
|
62
|
|
|
|
|
80
|
|
|
62
|
|
|
|
|
1334
|
|
5
|
|
|
|
|
|
|
|
6
|
47
|
|
|
47
|
|
209
|
use Config; |
|
47
|
|
|
|
|
54
|
|
|
47
|
|
|
|
|
1678
|
|
7
|
47
|
|
|
47
|
|
9986
|
use IO::Handle; |
|
47
|
|
|
|
|
94160
|
|
|
47
|
|
|
|
|
1635
|
|
8
|
|
|
|
|
|
|
|
9
|
47
|
|
|
47
|
|
261
|
use base 'TAP::Parser::Iterator'; |
|
47
|
|
|
|
|
66
|
|
|
47
|
|
|
|
|
7755
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $IS_WIN32 = ( $^O =~ /^(MS)?Win32$/ ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
TAP::Parser::Iterator::Process - Iterator for process-based TAP sources |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 3.38 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '3.38'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use TAP::Parser::Iterator::Process; |
28
|
|
|
|
|
|
|
my %args = ( |
29
|
|
|
|
|
|
|
command => ['python', 'setup.py', 'test'], |
30
|
|
|
|
|
|
|
merge => 1, |
31
|
|
|
|
|
|
|
setup => sub { ... }, |
32
|
|
|
|
|
|
|
teardown => sub { ... }, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
my $it = TAP::Parser::Iterator::Process->new(\%args); |
35
|
|
|
|
|
|
|
my $line = $it->next; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This is a simple iterator wrapper for executing external processes, used by |
40
|
|
|
|
|
|
|
L. Unless you're writing a plugin or subclassing, you probably |
41
|
|
|
|
|
|
|
won't need to use this module directly. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 Class Methods |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head3 C |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Create an iterator. Expects one argument containing a hashref of the form: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
command => \@command_to_execute |
52
|
|
|
|
|
|
|
merge => $attempt_merge_stderr_and_stdout? |
53
|
|
|
|
|
|
|
setup => $callback_to_setup_command |
54
|
|
|
|
|
|
|
teardown => $callback_to_teardown_command |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Tries to uses L & L to communicate with the spawned |
57
|
|
|
|
|
|
|
process if they are available. Falls back onto C. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 Instance Methods |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head3 C |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Iterate through the process output, of course. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head3 C |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Iterate raw input without applying any fixes for quirky input syntax. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head3 C |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Get the wait status for this iterator's process. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head3 C |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Get the exit status for this iterator's process. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
|
81
|
47
|
|
|
47
|
|
221
|
no warnings 'uninitialized'; |
|
47
|
|
|
|
|
63
|
|
|
47
|
|
|
|
|
11971
|
|
82
|
|
|
|
|
|
|
# get around a catch22 in the test suite that causes failures on Win32: |
83
|
|
|
|
|
|
|
local $SIG{__DIE__} = undef; |
84
|
|
|
|
|
|
|
eval { require POSIX; &POSIX::WEXITSTATUS(0) }; |
85
|
|
|
|
|
|
|
if ($@) { |
86
|
|
|
|
|
|
|
*_wait2exit = sub { $_[1] >> 8 }; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
255
|
|
|
255
|
|
1523
|
*_wait2exit = sub { POSIX::WEXITSTATUS( $_[1] ) } |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _use_open3 { |
94
|
219
|
|
|
219
|
|
839
|
my $self = shift; |
95
|
219
|
100
|
66
|
|
|
3467
|
return unless $Config{d_fork} || $IS_WIN32; |
96
|
211
|
|
|
|
|
848
|
for my $module (qw( IPC::Open3 IO::Select )) { |
97
|
415
|
|
|
27
|
|
29894
|
eval "use $module"; |
|
25
|
|
|
26
|
|
10470
|
|
|
25
|
|
|
4
|
|
49989
|
|
|
25
|
|
|
4
|
|
961
|
|
|
24
|
|
|
4
|
|
9110
|
|
|
24
|
|
|
4
|
|
26267
|
|
|
24
|
|
|
3
|
|
682
|
|
|
2
|
|
|
3
|
|
4
|
|
|
2
|
|
|
3
|
|
113
|
|
|
2
|
|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
26
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
98
|
415
|
50
|
|
|
|
1514
|
return if $@; |
99
|
|
|
|
|
|
|
} |
100
|
211
|
|
|
|
|
645
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
my $got_unicode; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _get_unicode { |
107
|
9
|
100
|
|
9
|
|
78
|
return $got_unicode if defined $got_unicode; |
108
|
8
|
|
|
|
|
480
|
eval 'use Encode qw(decode_utf8);'; |
109
|
8
|
50
|
|
|
|
49
|
$got_unicode = $@ ? 0 : 1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# new() implementation supplied by TAP::Object |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _initialize { |
117
|
262
|
|
|
262
|
|
421
|
my ( $self, $args ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
262
|
100
|
|
|
|
543
|
my @command = @{ delete $args->{command} || [] } |
|
261
|
100
|
|
|
|
1515
|
|
120
|
|
|
|
|
|
|
or die "Must supply a command to execute"; |
121
|
|
|
|
|
|
|
|
122
|
260
|
|
|
|
|
957
|
$self->{command} = [@command]; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Private. Used to frig with chunk size during testing. |
125
|
260
|
|
100
|
|
|
1680
|
my $chunk_size = delete $args->{_chunk_size} || 65536; |
126
|
|
|
|
|
|
|
|
127
|
260
|
|
|
|
|
551
|
my $merge = delete $args->{merge}; |
128
|
260
|
|
|
|
|
320
|
my ( $pid, $err, $sel ); |
129
|
|
|
|
|
|
|
|
130
|
260
|
100
|
|
|
|
871
|
if ( my $setup = delete $args->{setup} ) { |
131
|
217
|
|
|
|
|
640
|
$setup->(@command); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
260
|
|
|
|
|
2733
|
my $out = IO::Handle->new; |
135
|
|
|
|
|
|
|
|
136
|
260
|
100
|
|
|
|
8574
|
if ( $self->_use_open3 ) { |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# HOTPATCH {{{ |
139
|
209
|
|
|
|
|
435
|
my $xclose = \&IPC::Open3::xclose; |
140
|
46
|
|
|
46
|
|
237
|
no warnings; |
|
46
|
|
|
|
|
75
|
|
|
46
|
|
|
|
|
2070
|
|
141
|
|
|
|
|
|
|
local *IPC::Open3::xclose = sub { |
142
|
569
|
|
|
569
|
|
830535
|
my $fh = shift; |
143
|
46
|
|
|
46
|
|
174
|
no strict 'refs'; |
|
46
|
|
|
|
|
146
|
|
|
46
|
|
|
|
|
36065
|
|
144
|
568
|
100
|
|
|
|
2763
|
return if ( fileno($fh) == fileno(STDIN) ); |
145
|
365
|
|
|
|
|
1534
|
$xclose->($fh); |
146
|
209
|
|
|
|
|
1366
|
}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# }}} |
149
|
|
|
|
|
|
|
|
150
|
208
|
50
|
|
|
|
697
|
if ($IS_WIN32) { |
151
|
5
|
0
|
|
|
|
28
|
$err = $merge ? '' : '>&STDERR'; |
152
|
5
|
|
|
|
|
9
|
eval { |
153
|
5
|
0
|
|
|
|
115
|
$pid = open3( |
154
|
|
|
|
|
|
|
'<&STDIN', $out, $merge ? '' : $err, |
155
|
|
|
|
|
|
|
@command |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
}; |
158
|
5
|
0
|
|
|
|
38
|
die "Could not execute (@command): $@" if $@; |
159
|
5
|
0
|
|
|
|
10
|
if ( $] >= 5.006 ) { |
160
|
5
|
|
|
|
|
250
|
binmode($out, ":crlf"); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
208
|
100
|
|
|
|
854
|
$err = $merge ? '' : IO::Handle->new; |
165
|
208
|
|
|
|
|
2464
|
eval { $pid = open3( '<&STDIN', $out, $err, @command ); }; |
|
208
|
|
|
|
|
992
|
|
166
|
208
|
50
|
|
|
|
10213
|
die "Could not execute (@command): $@" if $@; |
167
|
208
|
100
|
|
|
|
2845
|
$sel = $merge ? undef : IO::Select->new( $out, $err ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
56
|
|
|
|
|
511
|
$err = ''; |
172
|
|
|
|
|
|
|
my $command |
173
|
56
|
100
|
|
|
|
138
|
= join( ' ', map { $_ =~ /\s/ ? qq{"$_"} : $_ } @command ); |
|
123
|
|
|
|
|
613
|
|
174
|
56
|
50
|
|
|
|
254676
|
open( $out, "$command|" ) |
175
|
|
|
|
|
|
|
or die "Could not execute ($command): $!"; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
259
|
|
|
|
|
16339
|
$self->{out} = $out; |
179
|
259
|
|
|
|
|
987
|
$self->{err} = $err; |
180
|
259
|
|
|
|
|
794
|
$self->{sel} = $sel; |
181
|
259
|
|
|
|
|
593
|
$self->{pid} = $pid; |
182
|
259
|
|
|
|
|
794
|
$self->{exit} = undef; |
183
|
259
|
|
|
|
|
1061
|
$self->{chunk_size} = $chunk_size; |
184
|
|
|
|
|
|
|
|
185
|
259
|
100
|
|
|
|
1987
|
if ( my $teardown = delete $args->{teardown} ) { |
186
|
|
|
|
|
|
|
$self->{teardown} = sub { |
187
|
211
|
|
|
212
|
|
1355
|
$teardown->(@command); |
188
|
216
|
|
|
|
|
2672
|
}; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
259
|
|
|
|
|
9689
|
return $self; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head3 C |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Upgrade the input stream to handle UTF8. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub handle_unicode { |
201
|
17
|
|
|
18
|
1
|
56
|
my $self = shift; |
202
|
|
|
|
|
|
|
|
203
|
17
|
100
|
|
|
|
165
|
if ( $self->{sel} ) { |
204
|
6
|
50
|
|
|
|
51
|
if ( _get_unicode() ) { |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Make sure our iterator has been constructed and... |
207
|
6
|
|
33
|
|
|
21
|
my $next = $self->{_next} ||= $self->_next; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# ...wrap it to do UTF8 casting |
210
|
|
|
|
|
|
|
$self->{_next} = sub { |
211
|
10
|
|
|
12
|
|
30
|
my $line = $next->(); |
212
|
10
|
100
|
|
|
|
32
|
return decode_utf8($line) if defined $line; |
213
|
6
|
|
|
|
|
132
|
return; |
214
|
6
|
|
|
|
|
229
|
}; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
14
|
50
|
|
|
|
128
|
if ( $] >= 5.008 ) { |
219
|
14
|
|
|
|
|
1771
|
eval 'binmode($self->{out}, ":utf8")'; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
############################################################################## |
226
|
|
|
|
|
|
|
|
227
|
221
|
|
|
222
|
1
|
1174
|
sub wait { shift->{wait} } |
228
|
224
|
|
|
225
|
1
|
7723
|
sub exit { shift->{exit} } |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub _next { |
231
|
256
|
|
|
257
|
|
2058
|
my $self = shift; |
232
|
|
|
|
|
|
|
|
233
|
256
|
50
|
|
|
|
918
|
if ( my $out = $self->{out} ) { |
234
|
256
|
100
|
|
|
|
774
|
if ( my $sel = $self->{sel} ) { |
235
|
159
|
|
|
|
|
244
|
my $err = $self->{err}; |
236
|
159
|
|
|
|
|
509
|
my @buf = (); |
237
|
159
|
|
|
|
|
372
|
my $partial = ''; # Partial line |
238
|
159
|
|
|
|
|
246
|
my $chunk_size = $self->{chunk_size}; |
239
|
|
|
|
|
|
|
return sub { |
240
|
845
|
100
|
|
847
|
|
2129
|
return shift @buf if @buf; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
READ: |
243
|
421
|
|
|
|
|
1274
|
while ( my @ready = $sel->can_read ) { |
244
|
843
|
|
|
|
|
3240612
|
for my $fh (@ready) { |
245
|
979
|
|
|
|
|
127899
|
my $got = sysread $fh, my ($chunk), $chunk_size; |
246
|
|
|
|
|
|
|
|
247
|
979
|
100
|
|
|
|
2079
|
if ( $got == 0 ) { |
|
|
100
|
|
|
|
|
|
248
|
307
|
|
|
|
|
1012
|
$sel->remove($fh); |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
elsif ( $fh == $err ) { |
251
|
11
|
|
|
|
|
143
|
print STDERR $chunk; # echo STDERR |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
else { |
254
|
667
|
|
|
|
|
1016
|
$chunk = $partial . $chunk; |
255
|
667
|
|
|
|
|
971
|
$partial = ''; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# Make sure we have a complete line |
258
|
667
|
100
|
|
|
|
1678
|
unless ( substr( $chunk, -1, 1 ) eq "\n" ) { |
259
|
474
|
|
|
|
|
455
|
my $nl = rindex $chunk, "\n"; |
260
|
474
|
100
|
|
|
|
650
|
if ( $nl == -1 ) { |
261
|
428
|
|
|
|
|
377
|
$partial = $chunk; |
262
|
428
|
|
|
|
|
545
|
redo READ; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
else { |
265
|
49
|
|
|
|
|
276
|
$partial = substr( $chunk, $nl + 1 ); |
266
|
49
|
|
|
|
|
103
|
$chunk = substr( $chunk, 0, $nl ); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
242
|
|
|
|
|
1231
|
push @buf, split /\n/, $chunk; |
271
|
242
|
50
|
|
|
|
1614
|
return shift @buf if @buf; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# Return partial last line |
277
|
182
|
100
|
|
|
|
4125
|
if ( length $partial ) { |
278
|
30
|
|
|
|
|
70
|
my $last = $partial; |
279
|
30
|
|
|
|
|
286
|
$partial = ''; |
280
|
30
|
|
|
|
|
117
|
return $last; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
155
|
|
|
|
|
521
|
$self->_finish; |
284
|
155
|
|
|
|
|
2669
|
return; |
285
|
159
|
|
|
|
|
1733
|
}; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
else { |
288
|
|
|
|
|
|
|
return sub { |
289
|
665
|
100
|
|
667
|
|
2325347
|
if ( defined( my $line = <$out> ) ) { |
290
|
569
|
|
|
|
|
1864
|
chomp $line; |
291
|
569
|
|
|
|
|
2750
|
return $line; |
292
|
|
|
|
|
|
|
} |
293
|
99
|
|
|
|
|
799
|
$self->_finish; |
294
|
99
|
|
|
|
|
1377
|
return; |
295
|
100
|
|
|
|
|
1165
|
}; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
else { |
299
|
|
|
|
|
|
|
return sub { |
300
|
3
|
|
|
5
|
|
10
|
$self->_finish; |
301
|
3
|
|
|
|
|
177
|
return; |
302
|
3
|
|
|
|
|
43
|
}; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub next_raw { |
307
|
1507
|
|
|
1509
|
1
|
2504
|
my $self = shift; |
308
|
1507
|
|
66
|
|
|
5817
|
return ( $self->{_next} ||= $self->_next )->(); |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub _finish { |
312
|
251
|
|
|
253
|
|
475
|
my $self = shift; |
313
|
|
|
|
|
|
|
|
314
|
251
|
|
|
|
|
1176
|
my $status = $?; |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# Avoid circular refs |
317
|
3
|
|
|
5
|
|
161
|
$self->{_next} = sub {return} |
318
|
251
|
50
|
|
|
|
2236
|
if $] >= 5.006; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
# If we have a subprocess we need to wait for it to terminate |
321
|
251
|
100
|
|
|
|
915
|
if ( defined $self->{pid} ) { |
322
|
200
|
50
|
|
|
|
11161
|
if ( $self->{pid} == waitpid( $self->{pid}, 0 ) ) { |
323
|
200
|
|
|
|
|
493
|
$status = $?; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
251
|
50
|
|
|
|
2490
|
( delete $self->{out} )->close if $self->{out}; |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# If we have an IO::Select we also have an error handle to close. |
330
|
251
|
100
|
|
|
|
9669
|
if ( $self->{sel} ) { |
331
|
155
|
|
|
|
|
635
|
( delete $self->{err} )->close; |
332
|
155
|
|
|
|
|
1221
|
delete $self->{sel}; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
else { |
335
|
99
|
|
|
|
|
222
|
$status = $?; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
# Sometimes we get -1 on Windows. Presumably that means status not |
339
|
|
|
|
|
|
|
# available. |
340
|
251
|
50
|
33
|
|
|
942
|
$status = 0 if $IS_WIN32 && $status == -1; |
341
|
|
|
|
|
|
|
|
342
|
251
|
|
|
|
|
1026
|
$self->{wait} = $status; |
343
|
251
|
|
|
|
|
1158
|
$self->{exit} = $self->_wait2exit($status); |
344
|
|
|
|
|
|
|
|
345
|
251
|
100
|
|
|
|
1012
|
if ( my $teardown = $self->{teardown} ) { |
346
|
209
|
|
|
|
|
502
|
$teardown->(); |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
251
|
|
|
|
|
383
|
return $self; |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=head3 C |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
Return a list of filehandles that may be used upstream in a select() |
355
|
|
|
|
|
|
|
call to signal that this Iterator is ready. Iterators that are not |
356
|
|
|
|
|
|
|
handle based should return an empty list. |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
=cut |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
sub get_select_handles { |
361
|
18
|
|
|
20
|
1
|
96
|
my $self = shift; |
362
|
17
|
|
|
|
|
86
|
return grep $_, ( $self->{out}, $self->{err} ); |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
1; |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=head1 ATTRIBUTION |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
Originally ripped off from L. |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=head1 SEE ALSO |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
L, |
374
|
|
|
|
|
|
|
L, |
375
|
|
|
|
|
|
|
L, |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=cut |
378
|
|
|
|
|
|
|
|