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   269568 use strict;
  3         48  
  3         243  
4 3     3   27 use warnings;
  3         9  
  3         249  
5              
6 3     3   72 use Exporter;
  3         9  
  3         873  
7             our @ISA = qw(Exporter);
8             our @EXPORT = qw(future);
9              
10             our $VERSION = '0.12';
11              
12 3     3   6075 use overload '&{}' => sub { my $self = shift; sub { $self->join() } };
  3     2   4092  
  3         36  
  2         62  
  2         33  
  2         30  
13              
14 3     3   1404 use BGS ();
  3         12  
  3         429  
15              
16             sub new {
17 6     6 1 239 my $proto = shift;
18 6   33     45 my $class = ref($proto) || $proto;
19              
20 6         35 my $self = BGS::_bgs_call($_[0]);
21              
22 4         61 bless $self, $class;
23 4         47 return $self;
24             }
25              
26              
27             sub join {
28 4     4 1 76 my $self = shift;
29 4 50       101 if (exists $$self{result}) {
30 0         0 return $$self{result};
31             } else {
32 4         50 BGS::bgs_wait($$self{vpid});
33 4         401 return $$self{result};
34             }
35             }
36              
37              
38             sub cancel {
39 1     1 1 36 my $self = shift;
40 1         12 BGS::bgs_break($$self{vpid});
41             }
42              
43              
44             sub future(&) {
45 3     3 1 2523 __PACKAGE__->new($_[0]);
46             }
47              
48              
49             1;
50              
51              
52             __END__