ES6/Future.pm

filter: Statementstmt 40.9% 9 / 22 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 2 totaltotal 37.1% 13 / 35 CC 3 SCAR 10.6
CC
3
Cov
38%
to_future
6.0
from_future
3.0
__ANON__
2.0
CRAP 2.9
« ES6/Mojo.pm ↑ Summary ES6/EventLoopBase.pm »
1 package Promise::ES6::Future;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Promise::ES6::Future - Translation to/from L<Future>
11  
12 =head1 DESCRIPTION
13  
14 This module provides logic to convert between
15 promises and L<Future> instances.
16  
17 =head1 FUNCTIONS
18  
19 =head1 $promise = from_future( $FUTURE )
20  
21 Returns a L<Promise:ES6> instance from the given $FUTURE.
22 (If $FUTURE is not a L<Future> instance, $FUTURE is returned.)
23  
24 =cut
25  
26 1 ▶sub from_future {
Subroutine from_future: called CC=2 SCAR=10.9
Pod undocumented
27 1 my ($whatsit) = @_;
28  
29 1 ▶ return $whatsit if !$whatsit->isa('Future');
Branch: 1 branch
BranchTrueFalseTotal
unless $whatsit->isa("Future") 1 0 1
30  
31 0 local ($@, $!);
32 0 require Promise::ES6;
33  
34 0 ▶ return Promise::ES6->new( sub { () = $whatsit->then(@_) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 }
36  
37 =head1 $future = to_future( $PROMISE )
38  
39 Returns a L<Future> instance from the given $PROMISE.
40 (If $PROMISE is a Future instance, $PROMISE is returned.)
41  
42 Note that this function can work with promise objects that aren’t
43 L<Promise::ES6> instances. In fact, anything that I<isn’t> a Future
44 instance will cause this function to create a new Future.
45  
46 =cut
47  
48 0 ▶sub to_future {
Subroutine to_future: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my ($whatsit) = @_;
50  
51 0 ▶ return $whatsit if $whatsit->isa('Future');
Branch: 1 branch
BranchTrueFalseTotal
if $whatsit->isa("Future") 0 0 0
52  
53 0 local ($@, $!);
54 0 require Future;
55  
56 0 my $future = Future->new();
57  
58 $whatsit->then(
59 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 $future->done( $_[0] );
61 },
62 0 ▶ sub { $future->fail( $_[0] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 );
64  
65 0 return $future;
66 }
67  
68 1 1;
« ES6/Mojo.pm ↑ Summary ES6/EventLoopBase.pm »