Proc-Forkmap
This module supplies an easy to use map method that provides built-in forking and IPC.
EXAMPLES:
sub foo {
my ($x,$n) = (shift,1);
$n *= $_ for (@$x);
return $n;
}
@x = ([1..99],[100..199],[200..299]);
my $p = Proc::Forkmap->new;
my @rs = $p->fmap(\&foo,@x);
or,
package Foo;
sub new { return bless {}, shift};
sub bar { #do heavy calc stuff and max the CPU };
package main;
my $foo = Foo->new;
my @rs = Proc::Forkmap->new(max_kids => 5)->fmap(
sub { $foo->bar(@_) }, @x,
);
or,
my @rs = $p->fmap(sub { $_[0] ** $_[0] }, @x);
or,
#get stuff from the intertubes
sub bar {
my $t = shift;
my $s = Stock::Price->new;
... get historical stock prices ...
... do some analysis ...
baz($t,$sell_price);
}
#then save stuff to a data store
sub baz {
my ($t,$price) = @_;
my $conn = MongoDB::Connection->new;
my $db = $conn->stock;
my $bayes = $db->bayes;
$bayes->insert({symbol => $t, price => $price});
$conn->disconnect;
}
my $p = Proc::Forkmap->new(max_kids => 5, ipc => 0); # turn off IPC
$p->fmap(\&bar,qw/rht goog ^ixic ^dji yhoo aapl/);
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc Proc::Forkmap
You can also look for information at:
RT, CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Proc-Forkmap
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Proc-Forkmap
CPAN Ratings
http://cpanratings.perl.org/d/Proc-Forkmap
Search CPAN
http://search.cpan.org/dist/Proc-Forkmap/
LICENSE AND COPYRIGHT
Copyright (C) 2012 Andrew Shapiro
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.