Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 85 lines (66 sloc) 2.056 kB
2ea8fb8 @rcaputo Parameterize events the roles can emit. Create eg-15-ipc-run.pl and a…
authored
1 #!/usr/bin/perl
5b0127b @rcaputo Remove emit() from roles.
authored
2 # vim: ts=2 sw=2 noexpandtab
2ea8fb8 @rcaputo Parameterize events the roles can emit. Create eg-15-ipc-run.pl and a…
authored
3
4 # Demonstrate subprocesses without POE::Wheel::Run.
5 # Test case for upcoming Reflex::Run, which drives IPC::Run.
6
7 use warnings;
8 use strict;
9 use lib qw(../lib);
10
11 use Runner;
12
13 my $cmd = [
14 $^X, '-MTime::HiRes=sleep', '-wle',
15 q($|=1;) .
16 q(for (1..3) { $_ = qq[pid($$) moo($_)]; print; warn "$_\n"; sleep rand; })
17 ];
18
19 sub my_start {
20 my $cmd = shift;
21
22 use IPC::Run qw(start);
23 use Symbol qw(gensym);
24
25 my ($fh_in, $fh_out, $fh_err) = (gensym(), gensym(), gensym());
26
27 my $ipc_run = start(
28 $cmd,
29 '<pipe', $fh_in,
30 '>pipe', $fh_out,
31 '2>pipe', $fh_err,
32 ) or die "IPC::Run start() failed: $? ($!)";
33
34 return($ipc_run, $fh_in, $fh_out, $fh_err);
35 }
36
37 my ($ipc_run_1, $runner_1);
38 {
39 ($ipc_run_1, my($fh_in, $fh_out, $fh_err)) = my_start($cmd);
40
41 $runner_1 = Runner->new(
42 stdin => $fh_in,
43 stdout => $fh_out,
44 stderr => $fh_err,
45 pid => $ipc_run_1->{KIDS}[0]{PID},
46
47 on_stdout_closed => sub { print "runner_1 stdout closed\n" },
48 on_stderr_closed => sub { print "runner_1 stderr closed\n" },
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
49 on_stdout_data => sub { print "runner_1 stdout: ", $_[1]->octets() },
50 on_stderr_data => sub { print "runner_1 stderr: ", $_[1]->octets() },
2ea8fb8 @rcaputo Parameterize events the roles can emit. Create eg-15-ipc-run.pl and a…
authored
51
52 on_exit => sub {
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
53 my ($self, $child) = @_;
54 warn "runner_1 child ", $child->pid(), " exited: ", $child->exit(), "\n";
2ea8fb8 @rcaputo Parameterize events the roles can emit. Create eg-15-ipc-run.pl and a…
authored
55 $runner_1 = undef;
56 },
57 );
58 }
59
60 my ($ipc_run_2, $runner_2);
61 {
62 ($ipc_run_2, my($fh_in, $fh_out, $fh_err)) = my_start($cmd);
63
64 $runner_2 = Runner->new(
65 stdin => $fh_in,
66 stdout => $fh_out,
67 stderr => $fh_err,
68 pid => $ipc_run_2->{KIDS}[0]{PID},
69
70 on_stdout_closed => sub { print "runner_2 stdout closed\n" },
71 on_stderr_closed => sub { print "runner_2 stderr closed\n" },
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
72 on_stdout_data => sub { print "runner_2 stdout: ", $_[1]->octets() },
73 on_stderr_data => sub { print "runner_2 stderr: ", $_[1]->octets() },
2ea8fb8 @rcaputo Parameterize events the roles can emit. Create eg-15-ipc-run.pl and a…
authored
74
75 on_exit => sub {
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
76 my ($self, $child) = @_;
77 warn "runner_2 child ", $child->pid(), " exited: ", $child->exit(), "\n";
2ea8fb8 @rcaputo Parameterize events the roles can emit. Create eg-15-ipc-run.pl and a…
authored
78 $runner_2 = undef;
79 },
80 );
81 }
82
83 Reflex->run_all();
84 exit;
Something went wrong with that request. Please try again.