App::CLI::Plugin::Parallel::ForkManager - for App::CLI::Extension fork plugin module
1.01
# MyApp.pm package MyApp; use strict; use base qw(App::CLI::Extension); # extension method __PACKAGE__->load_plugins(qw(Parallel::ForkManager)); # extension method __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 { my ($pid, $ident) = @_; print "$ident PID[$pid] start\n"; }); $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; } 1; # myapp #!/usr/bin/perl use strict; use MyApp; MyApp->dispatch; # execute [kurt@localhost ~] ./myapp fork perl PID[3193] start cpan PID[3194] start foo PID[3195] start perl's status code: 200 perl PID[3193] finish. exit_value: 0 cpan's status code: 200 cpan PID[3194] finish. exit_value: 0 foo's status code: 200 cpan PID[3195] finish. exit_value: 0
App::CLI::Plugin::Parallel::ForkManager - Parallel::ForkManager plugin module
pm method setting
__PACKAGE__->config( parallel_fork_manager => $maxprocs );
or if --maxprocs option is defined. it applies.
# in MyApp/**.pm sub options { return ( "maxprocs=i" => "maxprocs" ) ; } # execute [kurt@localhost ~] ./myapp fork --maxprocs=10
return Parallel::ForkManager object.
Akira Horimoto
App::CLI::Extension Parallel::ForkManager
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Copyright (C) 2010 Akira Horimoto
To install App::CLI::Plugin::Parallel::ForkManager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::CLI::Plugin::Parallel::ForkManager
CPAN shell
perl -MCPAN -e shell install App::CLI::Plugin::Parallel::ForkManager
For more information on module installation, please visit the detailed CPAN module installation guide.