File Coverage

blib/lib/BGS/Future.pm
Criterion Covered Total %
statement 30 31 96.7
branch 1 2 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 4 4 100.0
total 46 50 92.0


line stmt bran cond sub pod time code
1             package BGS::Future;
2              
3 3     3   168705 use strict;
  3         33  
  3         75  
4 3     3   12 use warnings;
  3         6  
  3         66  
5              
6 3     3   12 use Exporter;
  3         15  
  3         285  
7             our @ISA = qw(Exporter);
8             our @EXPORT = qw(future);
9              
10             our $VERSION = '0.11';
11              
12 3     3   2727 use overload '&{}' => sub { my $self = shift; sub { $self->join() } };
  3     2   2613  
  3         21  
  2         49  
  2         32  
  2         18  
13              
14 3     3   879 use BGS ();
  3         15  
  3         765  
15              
16             sub new {
17 6     6 1 237 my $proto = shift;
18 6   33     34 my $class = ref($proto) || $proto;
19              
20 6         30 my $self = BGS::_bgs_call($_[0]);
21              
22 4         46 bless $self, $class;
23 4         57 return $self;
24             }
25              
26              
27             sub join {
28 4     4 1 54 my $self = shift;
29 4 50       87 if (exists $$self{result}) {
30 0         0 return $$self{result};
31             } else {
32 4         41 BGS::bgs_wait($$self{vpid});
33 4         72 return $$self{result};
34             }
35             }
36              
37              
38             sub cancel {
39 1     1 1 29 my $self = shift;
40 1         14 BGS::bgs_break($$self{vpid});
41             }
42              
43              
44             sub future(&) {
45 3     3 1 2426 __PACKAGE__->new($_[0]);
46             }
47              
48              
49             1;
50              
51              
52             __END__