line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Process::Async::Child; |
2
|
|
|
|
|
|
|
$Process::Async::Child::VERSION = '0.003'; |
3
|
1
|
|
|
1
|
|
19004
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use parent qw(IO::Async::Process); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Process::Async::Child - L subclass for handling communication between parent and worker |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 0.003 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
See L. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 send_command |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Helper for sending a command. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub send_command { |
31
|
1
|
|
|
1
|
1
|
1391
|
my ($self, $cmd, @data) = @_; |
32
|
1
|
|
|
|
|
10
|
$self->stdio->write(join(" ", $cmd, @data) . "\n") |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 on_read |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The read handler for processing messages sent by the child process. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub on_read { |
42
|
2
|
|
|
2
|
1
|
59160
|
my ($self, $stream, $buffref, $eof) = @_; |
43
|
2
|
|
|
|
|
43
|
while($$buffref =~ s/^(.*)\n//) { |
44
|
2
|
|
|
|
|
15
|
my ($k, $data) = split ' ', $1, 2; |
45
|
2
|
|
|
|
|
18
|
$self->debug_printf("Dealing with [%s] command", $k); |
46
|
2
|
50
|
|
|
|
25
|
if(my $method = $self->can('cmd_' . $k)) { |
47
|
2
|
|
|
|
|
11
|
$method->($self, $data); |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
0
|
$self->on_command( |
50
|
|
|
|
|
|
|
$k => $data |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
2
|
50
|
|
|
|
1821
|
$self->debug_printf("Input EOF") if $eof; |
55
|
2
|
|
|
|
|
7
|
return 0 |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 on_finish |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Handle finish events. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub on_finish { |
65
|
0
|
|
|
0
|
1
|
|
my ($self, $exitcode) = @_; |
66
|
0
|
|
|
|
|
|
$self->debug_printf("Finished - exit code %d", $exitcode); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 on_exception |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Handle exceptions. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub on_exception { |
76
|
0
|
|
|
0
|
1
|
|
my ($self, $exception, $errno, $exitcode) = @_; |
77
|
0
|
|
|
|
|
|
$self->debug_printf("Had exception [%s] errno %s exitcode %d", $exception, $errno, $exitcode); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |