X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote%2FFuture.pm;h=3392f68460cd78954adc2054691782134b846ecc;hb=9822fc762d19741060b1e731c405395938d810af;hp=3a2643b7f9ac700e8352ca17a39c4cfe87eec2f0;hpb=8ba4f2e3adb9a1fda64b463b34a4306c9034359a;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote/Future.pm b/lib/Object/Remote/Future.pm index 3a2643b..3392f68 100644 --- a/lib/Object/Remote/Future.pm +++ b/lib/Object/Remote/Future.pm @@ -34,9 +34,6 @@ package start; sub AUTOLOAD { my $invocant = shift; my ($method) = our $AUTOLOAD =~ /^start::(.+)$/; - if (ref($invocant) eq 'ARRAY') { - return [ map $_->${\"start::${method}"}, @$invocant ]; - } my $res; unless (eval { $res = $invocant->$method(@_); 1 }) { my $f = CPS::Future->new; @@ -51,4 +48,42 @@ sub AUTOLOAD { return $res; } +package maybe::start; + +sub AUTOLOAD { + my $invocant = shift; + my ($method) = our $AUTOLOAD =~ /^maybe::start::(.+)$/; + $method = "start::${method}" if ((caller(1)||'') eq 'start'); + $invocant->$method(@_); +} + +package then; + +sub AUTOLOAD { + my $invocant = shift; + my ($method) = our $AUTOLOAD =~ /^then::(.+)$/; + my @args = @_; + # Need two copies since if we're called on an already complete future + # $f will be freed immediately + my $ret = my $f = CPS::Future->new; + $invocant->on_fail(sub { $f->fail(@_); undef($f); }); + $invocant->on_done(sub { + my ($obj) = @_; + my $next = $obj->${\"start::${method}"}(@args); + $next->on_done(sub { $f->done(@_); undef($f); }); + $next->on_fail(sub { $f->fail(@_); undef($f); }); + }); + return $ret; +} + 1; + +=head1 NAME + +Object::Remote::Future - Asynchronous calling for L + +=head1 LAME + +Shipping prioritised over writing this part up. Blame mst. + +=cut