File Coverage

blib/lib/Object/Remote/Future.pm
Criterion Covered Total %
statement 47 56 83.9
branch 9 12 75.0
condition 5 9 55.5
subroutine 13 15 86.6
pod 0 3 0.0
total 74 95 77.8


line stmt bran cond sub pod time code
1             package Object::Remote::Future;
2              
3 15     15   81 use strict;
  15         25  
  15         527  
4 15     15   57 use warnings;
  15         85  
  15         624  
5 15     15   59 use base qw(Exporter);
  15         146  
  15         1797  
6              
7 15     15   236 use Object::Remote::Logging qw( :log router );
  15         22  
  15         122  
8              
9 15     15   57 BEGIN { router()->exclude_forwarding }
10              
11 15     15   8802 use Future;
  15         190444  
  15         10153  
12              
13             our @EXPORT = qw(future await_future await_all);
14              
15             sub future (&;$) {
16 136     136 0 977 my $f = $_[0]->(Object::Remote->current_loop->new_future);
17 136 100 50     1970 return $f if ((caller(1+($_[1]||0))||'') eq 'start');
18 110         492 await_future($f);
19             }
20              
21             sub await_future {
22 173     173 0 781 my $f = shift;
23 173         900 Object::Remote->current_loop->await($f);
24 173 100       1247 return wantarray ? $f->get : ($f->get)[0];
25             }
26              
27             sub await_all {
28 0     0 0 0 log_trace { my $l = @_; "await_all() invoked with '$l' futures to wait on" };
  0     2   0  
  2         423  
29 2         46 Object::Remote->current_loop->await_all(@_);
30 2         22 map $_->get, @_;
31             }
32              
33             package # hide from PAUSE
34             start;
35              
36             our $start = sub { my ($obj, $call) = (shift, shift); $obj->$call(@_); };
37              
38             sub AUTOLOAD {
39 13     13   155376 my $invocant = shift;
40 13         104 my ($method) = our $AUTOLOAD =~ /^start::(.+)$/;
41 13         26 my $res;
42 13 50       23 unless (eval { $res = $invocant->$method(@_); 1 }) {
  13         106  
  13         151  
43 0         0 my $f = Object::Remote->current_loop->new_future;
44 0         0 $f->fail($@);
45 0         0 return $f;
46             }
47 13 100 100     162 unless (Scalar::Util::blessed($res) and $res->isa('Future')) {
48 2         19 my $f = Object::Remote->current_loop->new_future;
49 2         41 $f->done($res);
50 2         149 return $f;
51             }
52 11         54 return $res;
53             }
54              
55             package # hide from PAUSE
56             maybe;
57              
58             sub start {
59 0     0   0 my ($obj, $call) = (shift, shift);
60 0 0 0     0 if ((caller(1)||'') eq 'start') {
61 0         0 $obj->$start::start($call => @_);
62             } else {
63 0         0 $obj->$call(@_);
64             }
65             }
66              
67             package # hide from PAUSE
68             maybe::start;
69              
70             sub AUTOLOAD {
71 48     48   1460 my $invocant = shift;
72 48         410 my ($method) = our $AUTOLOAD =~ /^maybe::start::(.+)$/;
73 48 100 50     288 $method = "start::${method}" if ((caller(1)||'') eq 'start');
74 48         641 $invocant->$method(@_);
75             }
76              
77             package # hide from PAUSE
78             then;
79              
80             sub AUTOLOAD {
81 2     2   6 my $invocant = shift;
82 2         12 my ($method) = our $AUTOLOAD =~ /^then::(.+)$/;
83 2         5 my @args = @_;
84             return $invocant->then(sub {
85 2     2   791 my ($obj) = @_;
86 2         5 return $obj->${\"start::${method}"}(@args);
  2         18  
87 2         20 });
88             }
89              
90             1;
91              
92             =head1 NAME
93              
94             Object::Remote::Future - Asynchronous calling for L
95              
96             =head1 LAME
97              
98             Shipping prioritised over writing this part up. Blame mst.
99              
100             =cut