line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TAP::Parser::Iterator::Process; |
2
|
|
|
|
|
|
|
|
3
|
62
|
|
|
62
|
|
102778
|
use strict; |
|
62
|
|
|
|
|
309
|
|
|
62
|
|
|
|
|
3025
|
|
4
|
62
|
|
|
62
|
|
460
|
use warnings; |
|
62
|
|
|
|
|
240
|
|
|
62
|
|
|
|
|
2053
|
|
5
|
|
|
|
|
|
|
|
6
|
47
|
|
|
47
|
|
439
|
use Config; |
|
47
|
|
|
|
|
136
|
|
|
47
|
|
|
|
|
2398
|
|
7
|
47
|
|
|
47
|
|
12665
|
use IO::Handle; |
|
47
|
|
|
|
|
132050
|
|
|
47
|
|
|
|
|
2635
|
|
8
|
|
|
|
|
|
|
|
9
|
47
|
|
|
47
|
|
454
|
use base 'TAP::Parser::Iterator'; |
|
47
|
|
|
|
|
139
|
|
|
47
|
|
|
|
|
14225
|
|
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.40_01 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '3.40_01'; |
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
|
|
415
|
no warnings 'uninitialized'; |
|
47
|
|
|
|
|
137
|
|
|
47
|
|
|
|
|
16482
|
|
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
|
257
|
|
|
257
|
|
2905
|
*_wait2exit = sub { POSIX::WEXITSTATUS( $_[1] ) } |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _use_open3 { |
94
|
220
|
|
|
220
|
|
1405
|
my $self = shift; |
95
|
220
|
100
|
66
|
|
|
4951
|
return unless $Config{d_fork} || $IS_WIN32; |
96
|
212
|
|
|
|
|
1490
|
for my $module (qw( IPC::Open3 IO::Select )) { |
97
|
417
|
|
|
27
|
|
41342
|
eval "use $module"; |
|
25
|
|
|
26
|
|
13508
|
|
|
25
|
|
|
4
|
|
85038
|
|
|
25
|
|
|
4
|
|
1239
|
|
|
24
|
|
|
4
|
|
11598
|
|
|
24
|
|
|
4
|
|
37899
|
|
|
24
|
|
|
3
|
|
880
|
|
|
2
|
|
|
3
|
|
8
|
|
|
2
|
|
|
3
|
|
139
|
|
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|
|
|
|
43
|
|
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
94
|
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
39
|
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
183
|
|
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
44
|
|
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
66
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
98
|
417
|
50
|
|
|
|
5591
|
return if $@; |
99
|
|
|
|
|
|
|
} |
100
|
212
|
|
|
|
|
1100
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
my $got_unicode; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _get_unicode { |
107
|
9
|
100
|
|
9
|
|
48
|
return $got_unicode if defined $got_unicode; |
108
|
8
|
|
|
|
|
2596
|
eval 'use Encode qw(decode_utf8);'; |
109
|
8
|
50
|
|
|
|
81
|
$got_unicode = $@ ? 0 : 1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# new() implementation supplied by TAP::Object |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _initialize { |
117
|
264
|
|
|
264
|
|
1094
|
my ( $self, $args ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
264
|
100
|
|
|
|
1032
|
my @command = @{ delete $args->{command} || [] } |
|
263
|
100
|
|
|
|
2256
|
|
120
|
|
|
|
|
|
|
or die "Must supply a command to execute"; |
121
|
|
|
|
|
|
|
|
122
|
262
|
|
|
|
|
1624
|
$self->{command} = [@command]; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Private. Used to frig with chunk size during testing. |
125
|
262
|
|
100
|
|
|
2522
|
my $chunk_size = delete $args->{_chunk_size} || 65536; |
126
|
|
|
|
|
|
|
|
127
|
262
|
|
|
|
|
1006
|
my $merge = delete $args->{merge}; |
128
|
262
|
|
|
|
|
931
|
my ( $pid, $err, $sel ); |
129
|
|
|
|
|
|
|
|
130
|
262
|
100
|
|
|
|
1253
|
if ( my $setup = delete $args->{setup} ) { |
131
|
219
|
|
|
|
|
1041
|
$setup->(@command); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
262
|
|
|
|
|
3610
|
my $out = IO::Handle->new; |
135
|
|
|
|
|
|
|
|
136
|
262
|
100
|
|
|
|
12905
|
if ( $self->_use_open3 ) { |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# HOTPATCH {{{ |
139
|
210
|
|
|
|
|
1909
|
my $xclose = \&IPC::Open3::xclose; |
140
|
46
|
|
|
46
|
|
464
|
no warnings; |
|
46
|
|
|
|
|
152
|
|
|
46
|
|
|
|
|
2835
|
|
141
|
|
|
|
|
|
|
local *IPC::Open3::xclose = sub { |
142
|
571
|
|
|
571
|
|
1130513
|
my $fh = shift; |
143
|
46
|
|
|
46
|
|
362
|
no strict 'refs'; |
|
46
|
|
|
|
|
147
|
|
|
46
|
|
|
|
|
53700
|
|
144
|
570
|
100
|
|
|
|
4683
|
return if ( fileno($fh) == fileno(STDIN) ); |
145
|
366
|
|
|
|
|
3053
|
$xclose->($fh); |
146
|
210
|
|
|
|
|
2143
|
}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# }}} |
149
|
|
|
|
|
|
|
|
150
|
209
|
50
|
|
|
|
1333
|
if ($IS_WIN32) { |
151
|
5
|
0
|
|
|
|
59
|
$err = $merge ? '' : '>&STDERR'; |
152
|
5
|
|
|
|
|
20
|
eval { |
153
|
5
|
0
|
|
|
|
174
|
$pid = open3( |
154
|
|
|
|
|
|
|
'<&STDIN', $out, $merge ? '' : $err, |
155
|
|
|
|
|
|
|
@command |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
}; |
158
|
5
|
0
|
|
|
|
80
|
die "Could not execute (@command): $@" if $@; |
159
|
5
|
0
|
|
|
|
29
|
if ( $] >= 5.006 ) { |
160
|
5
|
|
|
|
|
594
|
binmode($out, ":crlf"); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
209
|
100
|
|
|
|
1339
|
$err = $merge ? '' : IO::Handle->new; |
165
|
209
|
|
|
|
|
4656
|
eval { $pid = open3( '<&STDIN', $out, $err, @command ); }; |
|
209
|
|
|
|
|
1729
|
|
166
|
209
|
50
|
|
|
|
15005
|
die "Could not execute (@command): $@" if $@; |
167
|
209
|
100
|
|
|
|
4283
|
$sel = $merge ? undef : IO::Select->new( $out, $err ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
57
|
|
|
|
|
790
|
$err = ''; |
172
|
|
|
|
|
|
|
my $command |
173
|
57
|
100
|
|
|
|
260
|
= join( ' ', map { $_ =~ /\s/ ? qq{"$_"} : $_ } @command ); |
|
125
|
|
|
|
|
907
|
|
174
|
57
|
50
|
|
|
|
236079
|
open( $out, "$command|" ) |
175
|
|
|
|
|
|
|
or die "Could not execute ($command): $!"; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
261
|
|
|
|
|
33929
|
$self->{out} = $out; |
179
|
261
|
|
|
|
|
1992
|
$self->{err} = $err; |
180
|
261
|
|
|
|
|
1666
|
$self->{sel} = $sel; |
181
|
261
|
|
|
|
|
1530
|
$self->{pid} = $pid; |
182
|
261
|
|
|
|
|
2969
|
$self->{exit} = undef; |
183
|
261
|
|
|
|
|
1533
|
$self->{chunk_size} = $chunk_size; |
184
|
|
|
|
|
|
|
|
185
|
261
|
100
|
|
|
|
2968
|
if ( my $teardown = delete $args->{teardown} ) { |
186
|
|
|
|
|
|
|
$self->{teardown} = sub { |
187
|
213
|
|
|
214
|
|
2107
|
$teardown->(@command); |
188
|
218
|
|
|
|
|
3662
|
}; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
261
|
|
|
|
|
16028
|
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
|
19
|
|
|
20
|
1
|
215
|
my $self = shift; |
202
|
|
|
|
|
|
|
|
203
|
19
|
100
|
|
|
|
236
|
if ( $self->{sel} ) { |
204
|
6
|
50
|
|
|
|
139
|
if ( _get_unicode() ) { |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Make sure our iterator has been constructed and... |
207
|
6
|
|
33
|
|
|
43
|
my $next = $self->{_next} ||= $self->_next; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# ...wrap it to do UTF8 casting |
210
|
|
|
|
|
|
|
$self->{_next} = sub { |
211
|
10
|
|
|
12
|
|
75
|
my $line = $next->(); |
212
|
10
|
100
|
|
|
|
63
|
return decode_utf8($line) if defined $line; |
213
|
6
|
|
|
|
|
211
|
return; |
214
|
6
|
|
|
|
|
312
|
}; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
16
|
50
|
|
|
|
139
|
if ( $] >= 5.008 ) { |
219
|
16
|
|
|
|
|
2052
|
eval 'binmode($self->{out}, ":utf8")'; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
############################################################################## |
226
|
|
|
|
|
|
|
|
227
|
223
|
|
|
224
|
1
|
1678
|
sub wait { shift->{wait} } |
228
|
226
|
|
|
227
|
1
|
9335
|
sub exit { shift->{exit} } |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub _next { |
231
|
258
|
|
|
259
|
|
898
|
my $self = shift; |
232
|
|
|
|
|
|
|
|
233
|
258
|
50
|
|
|
|
1559
|
if ( my $out = $self->{out} ) { |
234
|
258
|
100
|
|
|
|
1962
|
if ( my $sel = $self->{sel} ) { |
235
|
159
|
|
|
|
|
559
|
my $err = $self->{err}; |
236
|
159
|
|
|
|
|
867
|
my @buf = (); |
237
|
159
|
|
|
|
|
933
|
my $partial = ''; # Partial line |
238
|
159
|
|
|
|
|
471
|
my $chunk_size = $self->{chunk_size}; |
239
|
|
|
|
|
|
|
return sub { |
240
|
845
|
100
|
|
847
|
|
4029
|
return shift @buf if @buf; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
READ: |
243
|
422
|
|
|
|
|
2710
|
while ( my @ready = $sel->can_read ) { |
244
|
844
|
|
|
|
|
5143136
|
for my $fh (@ready) { |
245
|
983
|
|
|
|
|
141739
|
my $got = sysread $fh, my ($chunk), $chunk_size; |
246
|
|
|
|
|
|
|
|
247
|
983
|
100
|
|
|
|
9284
|
if ( $got == 0 ) { |
|
|
100
|
|
|
|
|
|
248
|
307
|
|
|
|
|
1941
|
$sel->remove($fh); |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
elsif ( $fh == $err ) { |
251
|
11
|
|
|
|
|
176
|
print STDERR $chunk; # echo STDERR |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
else { |
254
|
671
|
|
|
|
|
2878
|
$chunk = $partial . $chunk; |
255
|
671
|
|
|
|
|
3290
|
$partial = ''; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# Make sure we have a complete line |
258
|
671
|
100
|
|
|
|
7829
|
unless ( substr( $chunk, -1, 1 ) eq "\n" ) { |
259
|
477
|
|
|
|
|
1967
|
my $nl = rindex $chunk, "\n"; |
260
|
477
|
100
|
|
|
|
1293
|
if ( $nl == -1 ) { |
261
|
431
|
|
|
|
|
1279
|
$partial = $chunk; |
262
|
431
|
|
|
|
|
1919
|
redo READ; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
else { |
265
|
49
|
|
|
|
|
355
|
$partial = substr( $chunk, $nl + 1 ); |
266
|
49
|
|
|
|
|
1956
|
$chunk = substr( $chunk, 0, $nl ); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
243
|
|
|
|
|
1972
|
push @buf, split /\n/, $chunk; |
271
|
243
|
50
|
|
|
|
5612
|
return shift @buf if @buf; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# Return partial last line |
277
|
182
|
100
|
|
|
|
10253
|
if ( length $partial ) { |
278
|
30
|
|
|
|
|
93
|
my $last = $partial; |
279
|
30
|
|
|
|
|
393
|
$partial = ''; |
280
|
30
|
|
|
|
|
279
|
return $last; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
155
|
|
|
|
|
1460
|
$self->_finish; |
284
|
155
|
|
|
|
|
3892
|
return; |
285
|
159
|
|
|
|
|
3287
|
}; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
else { |
288
|
|
|
|
|
|
|
return sub { |
289
|
681
|
100
|
|
683
|
|
2468482
|
if ( defined( my $line = <$out> ) ) { |
290
|
583
|
|
|
|
|
2728
|
chomp $line; |
291
|
583
|
|
|
|
|
3656
|
return $line; |
292
|
|
|
|
|
|
|
} |
293
|
101
|
|
|
|
|
903
|
$self->_finish; |
294
|
101
|
|
|
|
|
1594
|
return; |
295
|
102
|
|
|
|
|
1552
|
}; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
else { |
299
|
|
|
|
|
|
|
return sub { |
300
|
3
|
|
|
5
|
|
16
|
$self->_finish; |
301
|
3
|
|
|
|
|
236
|
return; |
302
|
3
|
|
|
|
|
54
|
}; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub next_raw { |
307
|
1523
|
|
|
1525
|
1
|
5855
|
my $self = shift; |
308
|
1523
|
|
66
|
|
|
9267
|
return ( $self->{_next} ||= $self->_next )->(); |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub _finish { |
312
|
253
|
|
|
255
|
|
963
|
my $self = shift; |
313
|
|
|
|
|
|
|
|
314
|
253
|
|
|
|
|
1508
|
my $status = $?; |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# Avoid circular refs |
317
|
3
|
|
|
5
|
|
214
|
$self->{_next} = sub {return} |
318
|
253
|
50
|
|
|
|
3548
|
if $] >= 5.006; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
# If we have a subprocess we need to wait for it to terminate |
321
|
253
|
100
|
|
|
|
2087
|
if ( defined $self->{pid} ) { |
322
|
201
|
50
|
|
|
|
17978
|
if ( $self->{pid} == waitpid( $self->{pid}, 0 ) ) { |
323
|
201
|
|
|
|
|
1140
|
$status = $?; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
253
|
50
|
|
|
|
4414
|
( delete $self->{out} )->close if $self->{out}; |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# If we have an IO::Select we also have an error handle to close. |
330
|
253
|
100
|
|
|
|
9808
|
if ( $self->{sel} ) { |
331
|
155
|
|
|
|
|
1379
|
( delete $self->{err} )->close; |
332
|
155
|
|
|
|
|
2762
|
delete $self->{sel}; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
else { |
335
|
101
|
|
|
|
|
404
|
$status = $?; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
# Sometimes we get -1 on Windows. Presumably that means status not |
339
|
|
|
|
|
|
|
# available. |
340
|
253
|
50
|
33
|
|
|
1527
|
$status = 0 if $IS_WIN32 && $status == -1; |
341
|
|
|
|
|
|
|
|
342
|
253
|
|
|
|
|
1775
|
$self->{wait} = $status; |
343
|
253
|
|
|
|
|
2319
|
$self->{exit} = $self->_wait2exit($status); |
344
|
|
|
|
|
|
|
|
345
|
253
|
100
|
|
|
|
1921
|
if ( my $teardown = $self->{teardown} ) { |
346
|
211
|
|
|
|
|
878
|
$teardown->(); |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
253
|
|
|
|
|
1218
|
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
|
162
|
my $self = shift; |
362
|
17
|
|
|
|
|
165
|
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
|
|
|
|
|
|
|
|