Acme-Fork-Lazy
view release on metacpan or search on metacpan
inc/Module/Install.pm view on Meta::CPAN
use FindBin;
sub autoload {
my $self = shift;
my $who = $self->_caller;
my $cwd = Cwd::cwd();
my $sym = "${who}::AUTOLOAD";
$sym->{$cwd} = sub {
my $pwd = Cwd::cwd();
if ( my $code = $sym->{$pwd} ) {
# delegate back to parent dirs
goto &$code unless $cwd eq $pwd;
}
$$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
unshift @_, ( $self, $1 );
goto &{$self->can('call')} unless uc($1) eq $1;
};
}
sub import {
my $class = shift;
lib/Acme/Fork/Lazy.pm view on Meta::CPAN
###
END {
wait_kids; # make sure we're not leaving behind any zombies
}
=head1 DESCRIPTION
We often want to fork a process with an expensive calculation. This involves making the child
write the answer back to the parent, who will then have to poll the child occasionally to check
if it answered back. There are abstractions, like L<Poe::Wheel::Run> (lovely if you're already
using L<POE>). This is another one, using lazy variables:
=head2 C<forked>
my $foo = forked { do_calculation() };
print "The answer was $foo\n";
C<forked> returns a lazy calculation that will wait on the child process and return its
result as a Perl data structure. If the child process isn't ready, then it will wait for it.
( run in 0.829 second using v1.01-cache-2.11-cpan-4d50c553e7e )