App-CLI-Plugin-Parallel-ForkManager
view release on metacpan or search on metacpan
lib/App/CLI/Plugin/Parallel/ForkManager.pm view on Meta::CPAN
__PACKAGE__->config( parallel_fork_manager => 5 );
1;
# MyApp/Fork.pm
package MyApp::Fork;
use strict;
use base qw(App::CLI::Command);
use LWP::UserAgent;
use HTTP::Request;
our %LINKS = (cpan => "http://search.cpan.org", perl => "http://www.perl.org", foo => "http://foo.foo/");
sub options { return ("maxprocs=i" => "maxprocs") };
sub run {
my($self, @argv) = @_;
$self->pm->run_on_start(sub {
lib/App/CLI/Plugin/Parallel/ForkManager.pm view on Meta::CPAN
$self->pm->run_on_finish(sub {
my ($pid, $exit_value, $ident) = @_;
print "$ident PID[$pid] finish. exit_value: $exit_value\n";
});
foreach my $key (keys %LINKS) {
my $pid = $self->pm->start($key) and next;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $LINKS{$key});
my $res = $ua->request($req);
if ($res->is_success) {
printf "%s's status code: %d\n", $key, $res->code;
} else {
printf "ERROR: $key %s\n", $res->status_line;
}
$self->pm->finish;
}
$self->pm->wait_all_children;
( run in 0.469 second using v1.01-cache-2.11-cpan-de7293f3b23 )