line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TAP::Parser::Iterator::Process; |
2
|
|
|
|
|
|
|
|
3
|
62
|
|
|
62
|
|
42539
|
use strict; |
|
62
|
|
|
|
|
99
|
|
|
62
|
|
|
|
|
2140
|
|
4
|
62
|
|
|
62
|
|
242
|
use warnings; |
|
62
|
|
|
|
|
94
|
|
|
62
|
|
|
|
|
1340
|
|
5
|
|
|
|
|
|
|
|
6
|
47
|
|
|
47
|
|
215
|
use Config; |
|
47
|
|
|
|
|
62
|
|
|
47
|
|
|
|
|
1755
|
|
7
|
47
|
|
|
47
|
|
11638
|
use IO::Handle; |
|
47
|
|
|
|
|
107999
|
|
|
47
|
|
|
|
|
1860
|
|
8
|
|
|
|
|
|
|
|
9
|
47
|
|
|
47
|
|
336
|
use base 'TAP::Parser::Iterator'; |
|
47
|
|
|
|
|
67
|
|
|
47
|
|
|
|
|
8880
|
|
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.39 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '3.39'; |
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
|
|
238
|
no warnings 'uninitialized'; |
|
47
|
|
|
|
|
72
|
|
|
47
|
|
|
|
|
12872
|
|
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
|
|
1507
|
*_wait2exit = sub { POSIX::WEXITSTATUS( $_[1] ) } |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _use_open3 { |
94
|
219
|
|
|
219
|
|
813
|
my $self = shift; |
95
|
219
|
100
|
66
|
|
|
3774
|
return unless $Config{d_fork} || $IS_WIN32; |
96
|
211
|
|
|
|
|
816
|
for my $module (qw( IPC::Open3 IO::Select )) { |
97
|
415
|
|
|
27
|
|
31546
|
eval "use $module"; |
|
25
|
|
|
26
|
|
11161
|
|
|
25
|
|
|
4
|
|
48732
|
|
|
25
|
|
|
4
|
|
914
|
|
|
24
|
|
|
4
|
|
8531
|
|
|
24
|
|
|
4
|
|
24651
|
|
|
24
|
|
|
3
|
|
648
|
|
|
2
|
|
|
3
|
|
4
|
|
|
2
|
|
|
3
|
|
149
|
|
|
2
|
|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
24
|
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
52
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
98
|
415
|
50
|
|
|
|
1473
|
return if $@; |
99
|
|
|
|
|
|
|
} |
100
|
211
|
|
|
|
|
701
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
my $got_unicode; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _get_unicode { |
107
|
9
|
100
|
|
9
|
|
83
|
return $got_unicode if defined $got_unicode; |
108
|
8
|
|
|
|
|
552
|
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
|
|
483
|
my ( $self, $args ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
262
|
100
|
|
|
|
532
|
my @command = @{ delete $args->{command} || [] } |
|
261
|
100
|
|
|
|
1700
|
|
120
|
|
|
|
|
|
|
or die "Must supply a command to execute"; |
121
|
|
|
|
|
|
|
|
122
|
260
|
|
|
|
|
1003
|
$self->{command} = [@command]; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Private. Used to frig with chunk size during testing. |
125
|
260
|
|
100
|
|
|
2004
|
my $chunk_size = delete $args->{_chunk_size} || 65536; |
126
|
|
|
|
|
|
|
|
127
|
260
|
|
|
|
|
577
|
my $merge = delete $args->{merge}; |
128
|
260
|
|
|
|
|
361
|
my ( $pid, $err, $sel ); |
129
|
|
|
|
|
|
|
|
130
|
260
|
100
|
|
|
|
949
|
if ( my $setup = delete $args->{setup} ) { |
131
|
217
|
|
|
|
|
728
|
$setup->(@command); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
260
|
|
|
|
|
2498
|
my $out = IO::Handle->new; |
135
|
|
|
|
|
|
|
|
136
|
260
|
100
|
|
|
|
8543
|
if ( $self->_use_open3 ) { |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# HOTPATCH {{{ |
139
|
209
|
|
|
|
|
451
|
my $xclose = \&IPC::Open3::xclose; |
140
|
46
|
|
|
46
|
|
262
|
no warnings; |
|
46
|
|
|
|
|
86
|
|
|
46
|
|
|
|
|
2132
|
|
141
|
|
|
|
|
|
|
local *IPC::Open3::xclose = sub { |
142
|
569
|
|
|
569
|
|
573139
|
my $fh = shift; |
143
|
46
|
|
|
46
|
|
186
|
no strict 'refs'; |
|
46
|
|
|
|
|
77
|
|
|
46
|
|
|
|
|
37720
|
|
144
|
568
|
100
|
|
|
|
2859
|
return if ( fileno($fh) == fileno(STDIN) ); |
145
|
365
|
|
|
|
|
1673
|
$xclose->($fh); |
146
|
209
|
|
|
|
|
1290
|
}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# }}} |
149
|
|
|
|
|
|
|
|
150
|
208
|
50
|
|
|
|
855
|
if ($IS_WIN32) { |
151
|
5
|
0
|
|
|
|
34
|
$err = $merge ? '' : '>&STDERR'; |
152
|
5
|
|
|
|
|
9
|
eval { |
153
|
5
|
0
|
|
|
|
121
|
$pid = open3( |
154
|
|
|
|
|
|
|
'<&STDIN', $out, $merge ? '' : $err, |
155
|
|
|
|
|
|
|
@command |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
}; |
158
|
5
|
0
|
|
|
|
54
|
die "Could not execute (@command): $@" if $@; |
159
|
5
|
0
|
|
|
|
10
|
if ( $] >= 5.006 ) { |
160
|
5
|
|
|
|
|
283
|
binmode($out, ":crlf"); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
208
|
100
|
|
|
|
858
|
$err = $merge ? '' : IO::Handle->new; |
165
|
208
|
|
|
|
|
2447
|
eval { $pid = open3( '<&STDIN', $out, $err, @command ); }; |
|
208
|
|
|
|
|
1075
|
|
166
|
208
|
50
|
|
|
|
10401
|
die "Could not execute (@command): $@" if $@; |
167
|
208
|
100
|
|
|
|
3128
|
$sel = $merge ? undef : IO::Select->new( $out, $err ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
56
|
|
|
|
|
598
|
$err = ''; |
172
|
|
|
|
|
|
|
my $command |
173
|
56
|
100
|
|
|
|
146
|
= join( ' ', map { $_ =~ /\s/ ? qq{"$_"} : $_ } @command ); |
|
123
|
|
|
|
|
527
|
|
174
|
56
|
50
|
|
|
|
122838
|
open( $out, "$command|" ) |
175
|
|
|
|
|
|
|
or die "Could not execute ($command): $!"; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
259
|
|
|
|
|
17903
|
$self->{out} = $out; |
179
|
259
|
|
|
|
|
1258
|
$self->{err} = $err; |
180
|
259
|
|
|
|
|
853
|
$self->{sel} = $sel; |
181
|
259
|
|
|
|
|
666
|
$self->{pid} = $pid; |
182
|
259
|
|
|
|
|
810
|
$self->{exit} = undef; |
183
|
259
|
|
|
|
|
728
|
$self->{chunk_size} = $chunk_size; |
184
|
|
|
|
|
|
|
|
185
|
259
|
100
|
|
|
|
1540
|
if ( my $teardown = delete $args->{teardown} ) { |
186
|
|
|
|
|
|
|
$self->{teardown} = sub { |
187
|
211
|
|
|
212
|
|
1260
|
$teardown->(@command); |
188
|
216
|
|
|
|
|
2493
|
}; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
259
|
|
|
|
|
10998
|
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
|
40
|
my $self = shift; |
202
|
|
|
|
|
|
|
|
203
|
17
|
100
|
|
|
|
141
|
if ( $self->{sel} ) { |
204
|
6
|
50
|
|
|
|
50
|
if ( _get_unicode() ) { |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Make sure our iterator has been constructed and... |
207
|
6
|
|
33
|
|
|
24
|
my $next = $self->{_next} ||= $self->_next; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# ...wrap it to do UTF8 casting |
210
|
|
|
|
|
|
|
$self->{_next} = sub { |
211
|
10
|
|
|
12
|
|
35
|
my $line = $next->(); |
212
|
10
|
100
|
|
|
|
62
|
return decode_utf8($line) if defined $line; |
213
|
6
|
|
|
|
|
175
|
return; |
214
|
6
|
|
|
|
|
245
|
}; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
14
|
50
|
|
|
|
82
|
if ( $] >= 5.008 ) { |
219
|
14
|
|
|
|
|
1278
|
eval 'binmode($self->{out}, ":utf8")'; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
############################################################################## |
226
|
|
|
|
|
|
|
|
227
|
221
|
|
|
222
|
1
|
1062
|
sub wait { shift->{wait} } |
228
|
224
|
|
|
225
|
1
|
5613
|
sub exit { shift->{exit} } |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub _next { |
231
|
256
|
|
|
257
|
|
497
|
my $self = shift; |
232
|
|
|
|
|
|
|
|
233
|
256
|
50
|
|
|
|
860
|
if ( my $out = $self->{out} ) { |
234
|
256
|
100
|
|
|
|
741
|
if ( my $sel = $self->{sel} ) { |
235
|
159
|
|
|
|
|
224
|
my $err = $self->{err}; |
236
|
159
|
|
|
|
|
529
|
my @buf = (); |
237
|
159
|
|
|
|
|
386
|
my $partial = ''; # Partial line |
238
|
159
|
|
|
|
|
263
|
my $chunk_size = $self->{chunk_size}; |
239
|
|
|
|
|
|
|
return sub { |
240
|
845
|
100
|
|
847
|
|
2031
|
return shift @buf if @buf; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
READ: |
243
|
421
|
|
|
|
|
1448
|
while ( my @ready = $sel->can_read ) { |
244
|
848
|
|
|
|
|
5178691
|
for my $fh (@ready) { |
245
|
979
|
|
|
|
|
124925
|
my $got = sysread $fh, my ($chunk), $chunk_size; |
246
|
|
|
|
|
|
|
|
247
|
979
|
100
|
|
|
|
2511
|
if ( $got == 0 ) { |
|
|
100
|
|
|
|
|
|
248
|
307
|
|
|
|
|
1013
|
$sel->remove($fh); |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
elsif ( $fh == $err ) { |
251
|
11
|
|
|
|
|
193
|
print STDERR $chunk; # echo STDERR |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
else { |
254
|
667
|
|
|
|
|
1241
|
$chunk = $partial . $chunk; |
255
|
667
|
|
|
|
|
1163
|
$partial = ''; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# Make sure we have a complete line |
258
|
667
|
100
|
|
|
|
11409
|
unless ( substr( $chunk, -1, 1 ) eq "\n" ) { |
259
|
473
|
|
|
|
|
519
|
my $nl = rindex $chunk, "\n"; |
260
|
473
|
100
|
|
|
|
725
|
if ( $nl == -1 ) { |
261
|
428
|
|
|
|
|
504
|
$partial = $chunk; |
262
|
428
|
|
|
|
|
1138
|
redo READ; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
else { |
265
|
48
|
|
|
|
|
332
|
$partial = substr( $chunk, $nl + 1 ); |
266
|
48
|
|
|
|
|
120
|
$chunk = substr( $chunk, 0, $nl ); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
242
|
|
|
|
|
1522
|
push @buf, split /\n/, $chunk; |
271
|
242
|
50
|
|
|
|
1655
|
return shift @buf if @buf; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# Return partial last line |
277
|
182
|
100
|
|
|
|
4348
|
if ( length $partial ) { |
278
|
30
|
|
|
|
|
61
|
my $last = $partial; |
279
|
30
|
|
|
|
|
305
|
$partial = ''; |
280
|
30
|
|
|
|
|
144
|
return $last; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
155
|
|
|
|
|
608
|
$self->_finish; |
284
|
155
|
|
|
|
|
2704
|
return; |
285
|
159
|
|
|
|
|
2036
|
}; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
else { |
288
|
|
|
|
|
|
|
return sub { |
289
|
665
|
100
|
|
667
|
|
2184427
|
if ( defined( my $line = <$out> ) ) { |
290
|
569
|
|
|
|
|
1269
|
chomp $line; |
291
|
569
|
|
|
|
|
2477
|
return $line; |
292
|
|
|
|
|
|
|
} |
293
|
99
|
|
|
|
|
808
|
$self->_finish; |
294
|
99
|
|
|
|
|
1225
|
return; |
295
|
100
|
|
|
|
|
1201
|
}; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
else { |
299
|
|
|
|
|
|
|
return sub { |
300
|
3
|
|
|
5
|
|
10
|
$self->_finish; |
301
|
3
|
|
|
|
|
288
|
return; |
302
|
3
|
|
|
|
|
38
|
}; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub next_raw { |
307
|
1507
|
|
|
1509
|
1
|
2671
|
my $self = shift; |
308
|
1507
|
|
66
|
|
|
5751
|
return ( $self->{_next} ||= $self->_next )->(); |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub _finish { |
312
|
251
|
|
|
253
|
|
491
|
my $self = shift; |
313
|
|
|
|
|
|
|
|
314
|
251
|
|
|
|
|
1227
|
my $status = $?; |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# Avoid circular refs |
317
|
3
|
|
|
5
|
|
198
|
$self->{_next} = sub {return} |
318
|
251
|
50
|
|
|
|
2517
|
if $] >= 5.006; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
# If we have a subprocess we need to wait for it to terminate |
321
|
251
|
100
|
|
|
|
994
|
if ( defined $self->{pid} ) { |
322
|
200
|
50
|
|
|
|
8396
|
if ( $self->{pid} == waitpid( $self->{pid}, 0 ) ) { |
323
|
200
|
|
|
|
|
543
|
$status = $?; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
251
|
50
|
|
|
|
4963
|
( 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
|
|
|
|
7850
|
if ( $self->{sel} ) { |
331
|
155
|
|
|
|
|
670
|
( delete $self->{err} )->close; |
332
|
155
|
|
|
|
|
1178
|
delete $self->{sel}; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
else { |
335
|
99
|
|
|
|
|
202
|
$status = $?; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
# Sometimes we get -1 on Windows. Presumably that means status not |
339
|
|
|
|
|
|
|
# available. |
340
|
251
|
50
|
33
|
|
|
1132
|
$status = 0 if $IS_WIN32 && $status == -1; |
341
|
|
|
|
|
|
|
|
342
|
251
|
|
|
|
|
1047
|
$self->{wait} = $status; |
343
|
251
|
|
|
|
|
1327
|
$self->{exit} = $self->_wait2exit($status); |
344
|
|
|
|
|
|
|
|
345
|
251
|
100
|
|
|
|
1014
|
if ( my $teardown = $self->{teardown} ) { |
346
|
209
|
|
|
|
|
511
|
$teardown->(); |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
251
|
|
|
|
|
398
|
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
|
114
|
my $self = shift; |
362
|
17
|
|
|
|
|
125
|
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
|
|
|
|
|
|
|
|