AnyEvent-Subprocess
view release on metacpan or search on metacpan
examples/synopsis.pl view on Meta::CPAN
exit 0;
},
);
# start the child
my $run = $job->run;
# add watcher to print the next line we see on the child's stdout
$run->delegate('stdout')->handle->push_read( line => sub {
my ($h, $line) = @_;
say "The child said: $line";
});
# write to the child's stdin
$run->delegate('stdin')->handle->push_write("Hello, world!\n");
# close stdin after it has been written to the child
$run->delegate('stdin')->handle->on_drain(sub { $_[0]->close_fh });
# kill the child if it takes too long to produce a result
$killer = AnyEvent->timer( after => 2, interval => 0, cb => sub {
lib/AnyEvent/Subprocess.pm view on Meta::CPAN
exit 0;
},
);
# start the child
my $run = $job->run;
# add watcher to print the next line we see on the child's stdout
$run->delegate('stdout')->handle->push_read( line => sub {
my ($h, $line) = @_;
say "The child said: $line";
});
# write to the child's stdin
$run->delegate('stdin')->handle->push_write("Hello, world!\n");
# close stdin after it has been written to the child
$run->delegate('stdin')->handle->on_drain(sub { $_[0]->close_fh });
# kill the child if it takes too long to produce a result
my $killer = AnyEvent->timer( after => 42, interval => 0, cb => sub {
lib/AnyEvent/Subprocess.pm view on Meta::CPAN
direction => 'w',
replace => \*STDIN,
);
Every time you want to be able to write to STDIN is going to become
tiring after a while. When you load C<AnyEvent::Subprocess>, you also
load
L<AnyEvent::Subprocess::DefaultDelegate|AnyEvent::Subprocess::DefaultDelegates>.
This registers short names for each delegate and will cause
C<AnyEvent::Subprocess::Job> to build the actual instances
automatically. This means you can say C<'StandardHandles'> to get a
delegate for each of STDIN, STDOUT, and STDERR. If you want to know
how all the sugary names work, just open C<DefaultDelegates.pm> and
take a look. (The documentation for that module also covers that, as
well as how to define your own delegate builders.)
If you are too lazy to look -- there are delegates for giving the
child arbitrary sockets or pipes opened to arbitrary file descriptors
(so you can deal with more than stdin/stdout/stderr and communicate
bidirectionally between the parent and child), there is a delegate for
giving the child a pseudo-tty (which can run complicatged programs,
lib/AnyEvent/Subprocess/Done.pm view on Meta::CPAN
version 1.102912
=head1 SYNOPSIS
We are C<$done> in a sequence like:
my $job = AnyEvent::Subprocess->new ( ... );
my $run = $job->run;
$run->delegate('stdin')->push_write('Hello, my child!');
say "Running child as ", $run->child_pid;
$run->kill(11) if $you_enjoy_that_sort_of_thing;
my $done = $job->delegate('completion_condvar')->recv;
say "Child exited with signal ", $done->exit_signal;
say "Child produced some stdout: ",
$done->delegate('stdout_capture')->output;
=head1 DESCRIPTION
An instance of this class is returned to your C<on_completion>
callback when the child process exists.
=head1 METHODS
=head2 delegate( $name )
lib/AnyEvent/Subprocess/Job/Delegate/Timeout.pm view on Meta::CPAN
time_limit => 10, # 10 seconds
kill_with => 'FIRE', # may not be available on your OS
);
my $job = AnyEvent::Subprocess->new( delegates => [$timed], code => ... );
my $run = $job->run;
Later...
my $done = ...;
say 'your job took too long, so i killed it with fire'
if $done->delegate('tiemout')->timed_out;
=head1 ATTRIBUTES
=head2 time_limit
Number of seconds to allow the subprocess to run for. Required.
=head2 kill_with
lib/AnyEvent/Subprocess/Role/WithDelegates/Manager.pm view on Meta::CPAN
None by default, but you can request C<register_delegate> and
C<build_delegate>.
=head1 FUNCTIONS
=head2 register_delegate( $name, &$builder )
Register C<$builder> to build delegates named C<$name>. C<$builder>
is a coderef that is eventually called with the key/value pairs
supplied by the user. (The docs say this has to be a hashref, but it
can actually be any scalar value. Checking is up to you.) The
builder must return an instance of a class that does
L<AnyEvent::Subprocess::Delegate|AnyEvent::Subprocess::Delegate>,
although this condition is not checked by this module. (You will get
a type error when you are building the class that uses the delegate.)
In the common case where the args should be passed directly to some
class' constructor, you can just supply the class name as the
C<$builder>. C<new> will be called with any args the user supplies.
lib/AnyEvent/Subprocess/Running.pm view on Meta::CPAN
version 1.102912
=head1 SYNOPSIS
We are C<$run> in a sequence like:
my $job = AnyEvent::Subprocess->new ( ... );
my $run = $job->run;
$run->delegate('stdin')->push_write('Hello, my child!');
say "Running child as ", $run->child_pid;
$run->kill(11) if $you_enjoy_that_sort_of_thing;
my $done = $job->delegate('completion_condvar')->recv;
say "Child exited with signal ", $done->exit_signal;
=head1 DESCRIPTION
An instance of this class is returned when you start a subprocess. It
contains the child pid, any delegates that operate on the running
subprocess (handles, captures, etc.), and some control methods.
=head1 METHODS
=head2 child_pid
( run in 0.975 second using v1.01-cache-2.11-cpan-483215c6ad5 )