| 1 | package App::ForkProve::PipeIterator; | ||
| 2 | use strict; | ||
| 3 | use parent qw(TAP::Parser::Iterator::Stream); | ||
| 4 | |||
| 5 | sub new { | ||
| 6 | my($class, $fh, $pid) = @_; | ||
| 7 | my $self = $class->SUPER::new($fh); | ||
| 8 | $self->{pid} = $pid; | ||
| 9 | $self->{mypid} = $$; | ||
| 10 | $self; | ||
| 11 | } | ||
| 12 | |||
| 13 | sub get_select_handles { $_[0]->{fh} } | ||
| 14 | |||
| 15 | sub wait { $_[0]->_wait } | ||
| 16 | sub exit { $_[0]->_wait >> 8 } | ||
| 17 | |||
| 18 | sub _wait { | ||
| 19 | my $self = shift; | ||
| 20 | if (!defined $self->{wait}) { | ||
| 21 | waitpid $self->{pid}, 0; | ||
| 22 | $self->{wait} = $?; | ||
| 23 | } | ||
| 24 | return $self->{wait}; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub DESTROY { | ||
| 28 | return unless $_[0]->{mypid} == $$; | ||
| 29 | $_[0]->_wait; | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; | ||
| 33 |