forked from jhthorsen/mojo-ioloop-readwritefork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
116 lines (87 loc) · 2.59 KB
/
README
File metadata and controls
116 lines (87 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
NAME
Mojo::IOLoop::ReadWriteFork - Fork a process and read/write from it
VERSION
0.09
DESCRIPTION
This class enable you to fork children which you can write data to and
emit events when the child prints to STDERR or STDOUT.
Patches that enable the "read" event to see the difference between
STDERR and STDOUT are more than welcome.
SYNOPSIS
Standalone
my $fork = Mojo::IOLoop::ReadWriteFork->new;
my $cat_result = '';
$fork->on(error => sub {
my($fork, $error) = @_;
warn $error;
});
$fork->on(close => sub {
my($fork, $exit_value, $signal) = @_;
warn "got close event";
Mojo::IOLoop->stop;
});
$fork->on(read => sub {
my($fork, $buffer) = @_; # $buffer = both STDERR and STDOUT
$cat_result .= $buffer;
});
$fork->start(
program => 'bash',
program_args => [ -c => 'echo $YIKES foo bar baz' ],
conduit => 'pty',
);
In a Mojolicios::Controller
See
<https://github.com/jhthorsen/mojo-ioloop-readwritefork/tree/master/exam
ple/tail.pl>.
EVENTS
close
Emitted when the child process exit.
error
Emitted when when the there is an issue with creating, writing or
reading from the child process.
read
Emitted when the child has written a chunk of data to STDOUT or STDERR.
ATTRIBUTES
pid
Holds the child process ID.
reactor
Holds a Mojo::Reactor object. Default is:
Mojo::IOLoop->singleton->reactor;
METHODS
close
$self = $self->close("stdin");
Close STDIN stream to the child process immediately.
run
$self = $self->run($program, @program_args);
Simpler version of "start".
start
$self->start(
program => sub { my @program_args = @_; ... },
program_args => [ @data ],
);
$self->start(
program => $str,
program_args => [@str],
conduit => $str, # pipe or pty
raw => $bool,
clone_winsize_from => \*STDIN,
);
Used to fork and exec a child process.
raw and "clone_winsize_from|IO::Pty" only makes sense if "conduit" is
"pty".
write
$self = $self->write($chunk);
$self = $self->write($chunk, $cb);
Used to write data to the child process STDIN. An optional callback will
be called once STDIN is drained.
Example:
$self->write("some data\n", sub {
my ($self) = @_;
$self->close;
});
kill
$bool = $self->kill;
$bool = $self->kill(15); # default
Used to signal the child.
AUTHOR
Jan Henning Thorsen - "jhthorsen@cpan.org"