NAME
WWW::Webrobot::Forker - fork children and open socket to childrens STDOUT
SYNOPSIS
sub exec_child {
my ($child_id) = @_;
print "Childs $child_id answer\n";
}
sub readline {
my ($child_id, $line) = @_;
print ">> $line\n";
}
my $forker = Forker -> new();
$forker -> fork_children(1, \&exec_child);
$forker -> eventloop(\&readline);
DESCRIPTION
This module is used to fork off some worker processes.
METHODS
- my $obj = WWW::Webrobot::Forker -> new
-
Construct an object.
- $obj -> fork_children($count, \&child_function)
-
Forks off $count children. Each child executes \&function, then it terminates. STDOUT will be sent to the parent.
child_function takes the following parameters:
my ($child_id) = @_;
- $obj -> eventloop(\&readline);
-
Start the eventloop. Any data that is sent from a child via STDOUT will be forwarded to \&readline on a line by line basis. This method returns when all children closed STDOUT.
Readline takes the following parameters:
my ($child_id, $line) = @_;
Note 1:
$child_id
ofreadline()
is not the same as$child_id
ofchild_function()
Note 2: Currently no way is provided for the parent to send data to the child.