AnyEvent-Subprocess
view release on metacpan or search on metacpan
lib/AnyEvent/Subprocess/Job/Delegate/MonitorHandle.pm view on Meta::CPAN
default => sub { 'Line' },
);
sub parent_setup_hook {
my ($self, $job, $run) = @_;
my $handle = $run->delegate($self->handle)->handle;
if($self->when eq 'Line'){
my $reader; $reader = sub {
my ($h, $l, $eol) = @_;
$self->_run_callbacks($l, $eol);
$h->push_read(line => $reader);
};
$handle->push_read(line => $reader);
}
else {
$handle->on_read( sub {
my $h = shift;
$self->_run_callbacks( delete $h->{rbuf} );
return;
});
t/pty-basic.t view on Meta::CPAN
# XXX: I think this is weird. readline just blocks, even
# after the tty is closed / shutdown.
exit 0;
}
},
);
ok $proc;
my $run = $proc->run;
$run->delegate('pty')->handle->push_read( line => sub {
my ($h, $line, $eol) = @_;
is $line, 'Hello, parent!', 'got initial output';
$joiner->send_event( 'initial_output' );
$run->delegate('pty')->handle->push_write( "this is a test\n" );
$run->delegate('pty')->handle->push_shutdown;
} );
$run->delegate('pty')->handle->push_read( line => sub {
my ($h, $line, $eol) = @_;
is $line, 'this is a test', 'echoed input';
$joiner->send_event( 'echoed_input' );
} );
$run->delegate('comm')->handle->push_read( line => sub {
my ($h, $line, $eol) = @_;
is $line, 'got line: {this is a test}', 'process got input and cooked it';
$joiner->send_event( 'cooked_input' );
$run->delegate('comm')->handle->close_fh;
} );
my $timeout = AnyEvent->timer( after => 5, cb => sub {
diag "test subprocess failed to exit; this is strange";
done_testing;
exit 0;
});
( run in 1.341 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )