| 1 | package Future::Q; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use Future 0.29; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use parent "Future"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Devel::GlobalDestruction; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use Scalar::Util qw(refaddr blessed weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 20 | ▶ | use Try::Tiny (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 20 | our $VERSION = '0.120'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 20 | our @CARP_NOT = qw(Try::Tiny Future Future::PP Future::XS); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | our $OnError = undef; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | ## ** lexical attributes to avoid collision of names. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | my %failure_handled_for = (); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1086 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1086 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1086 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1086 | my $id = refaddr $self; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1086 | $failure_handled_for{$id} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1086 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1083 | ▶ | sub _q_go_super_DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_q_go_super_DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1083 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1083 | my $super_destroy = $self->can("SUPER::DESTROY"); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1083 | ▶ | goto $super_destroy if defined $super_destroy; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1083 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1083 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1083 | ▶ | if(in_global_destruction) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | goto \&_q_go_super_DESTROY; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1083 | my $id = refaddr $self; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1083 | ▶ | if($self->is_ready && $self->failure && !$failure_handled_for{$id}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->is_ready and $self->failure and not $failure_handled_for{$id}
$self->is_ready and $self->failure
MC/DC100%3/3
$self->is_ready and $self->failure and not $failure_handled_for{$id}
$self->is_ready
$self->failure
not $failure_handled_for{$id}
Truth table100%4/4
A and B and not(C)
A= $self->is_readyB= $self->failureC= not $failure_handled_for{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 104 | $self->_q_warn_failure(); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 104 | ▶ | my @failed_subfutures = Try::Tiny::try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 104 | $self->failed_futures; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 98 | ▶ | }Try::Tiny::catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 98 | (); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 104 | }; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 104 | foreach my $f (@failed_subfutures) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 16 | ▶ | $f->_q_warn_failure(is_subfuture => 1) if blessed($f) && $f->can('_q_warn_failure'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($f) and $f->can("_q_warn_failure")
MC/DC0%0/2
builtin::blessed($f) and $f->can("_q_warn_failure")
builtin::blessed($f)
$f->can("_q_warn_failure")
Truth table33%1/3
A and B
A= builtin::blessed($f)B= $f->can("_q_warn_failure")
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1083 | delete $failure_handled_for{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1083 | goto \&_q_go_super_DESTROY; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 576 | ▶ | sub _q_set_failure_handled { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_q_set_failure_handled: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 576 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 576 | $failure_handled_for{refaddr $self} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 120 | ▶ | sub _q_warn_failure { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_q_warn_failure: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 120 | my ($self, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 120 | ▶ | if($self->is_ready && $self->failure) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->is_ready and $self->failure
MC/DC0%0/2
$self->is_ready and $self->failure
$self->is_ready
$self->failure
Truth table33%1/3
A and B
A= $self->is_readyB= $self->failure
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 120 | my $failure = $self->failure; | |||||||||||||||||||||||||||||||||||||||||
| 65 | my $message = Carp::shortmess($options{is_subfuture} | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 120 | ▶ | ? "Failure of subfuture $self may not be handled: $failure subfuture may be lost" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | : "Failure of $self is not handled: $failure future is lost"); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 120 | ▶ | if(defined($OnError) && ref($OnError) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $Future::Q::OnError and ref $Future::Q::OnError eq "CODE"
MC/DC50%1/2
defined $Future::Q::OnError and ref $Future::Q::OnError eq "CODE"
defined $Future::Q::OnError
ref $Future::Q::OnError eq "CODE"
Truth table66%2/3
A and B
A= defined $Future::Q::OnErrorB= ref $Future::Q::OnError eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 117 | $OnError->($message); | |||||||||||||||||||||||||||||||||||||||||
| 70 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | warn $message; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 193 | ▶ | sub try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 193 | my ($class, $func, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 193 | ▶ | if(!defined($func) || ref($func) ne "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $func or ref $func ne "CODE"
MC/DC100%2/2
not defined $func or ref $func ne "CODE"
not defined $func
ref $func ne "CODE"
Truth table100%3/3
not(A) or B
A= not defined $funcB= ref $func ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | ▶ | $func = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | croak("func parameter for try() must be a code-ref"); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 193 | ▶ | my $result_future = Try::Tiny::try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 193 | my @results = $func->(@args); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 163 | ▶ | if(scalar(@results) == 1 && blessed($results[0]) && $results[0]->isa('Future')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
scalar @results == 1 and builtin::blessed($results[0]) and $results[0]->isa("Future")
scalar @results == 1 and builtin::blessed($results[0])
MC/DC66%2/3
scalar @results == 1 and builtin::blessed($results[0]) and $results[0]->isa("Future")
scalar @results == 1
builtin::blessed($results[0])
$results[0]->isa("Future")
Truth table75%3/4
A and B and C
A= scalar @results == 1B= builtin::blessed($results[0])C= $results[0]->isa("Future")
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 96 | return $results[0]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 67 | return $class->new->fulfill(@results); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 30 | ▶ | } Try::Tiny::catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 30 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 30 | return $class->new->reject($e); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 193 | }; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 193 | return $result_future; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub fcall { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fcall: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | goto $_[0]->can('try'); | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 327 | ▶ | sub then { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
then: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 327 | my ($self, $on_fulfilled, $on_rejected) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 327 | ▶ | if(defined($on_fulfilled) && ref($on_fulfilled) ne "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $on_fulfilled and ref $on_fulfilled ne "CODE"
MC/DC100%2/2
defined $on_fulfilled and ref $on_fulfilled ne "CODE"
defined $on_fulfilled
ref $on_fulfilled ne "CODE"
Truth table100%3/3
A and B
A= defined $on_fulfilledB= ref $on_fulfilled ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | $on_fulfilled = undef; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 327 | ▶ | if(defined($on_rejected) && ref($on_rejected) ne "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $on_rejected and ref $on_rejected ne "CODE"
MC/DC100%2/2
defined $on_rejected and ref $on_rejected ne "CODE"
defined $on_rejected
ref $on_rejected ne "CODE"
Truth table100%3/3
A and B
A= defined $on_rejectedB= ref $on_rejected ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $on_rejected = undef; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 327 | my $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 327 | $self->_q_set_failure_handled(); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 327 | my $next_future = $self->new; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 319 | ▶ | $self->on_ready(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 319 | my $invo_future = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 319 | ▶ | if($invo_future->is_cancelled) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 98 | ▶ | $next_future->cancel() if $next_future->is_pending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 98 | return; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 221 | my $return_future = $invo_future; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 221 | ▶ | if($invo_future->is_rejected && defined($on_rejected)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$invo_future->is_rejected and defined $on_rejected
MC/DC100%2/2
$invo_future->is_rejected and defined $on_rejected
$invo_future->is_rejected
defined $on_rejected
Truth table100%3/3
A and B
A= $invo_future->is_rejectedB= defined $on_rejected
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 79 | $return_future = $class->try($on_rejected, $invo_future->failure); | |||||||||||||||||||||||||||||||||||||||||
| 122 | ▶ | }elsif($invo_future->is_fulfilled && defined($on_fulfilled)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$invo_future->is_fulfilled and defined $on_fulfilled
MC/DC100%2/2
$invo_future->is_fulfilled and defined $on_fulfilled
$invo_future->is_fulfilled
defined $on_fulfilled
Truth table100%3/3
A and B
A= $invo_future->is_fulfilledB= defined $on_fulfilled
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 54 | $return_future = $class->try($on_fulfilled, $invo_future->get); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 221 | $next_future->resolve($return_future); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 327 | }); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 327 | ▶ | if($next_future->is_pending && $self->is_pending) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next_future->is_pending and $self->is_pending
MC/DC100%2/2
$next_future->is_pending and $self->is_pending
$next_future->is_pending
$self->is_pending
Truth table100%3/3
A and B
A= $next_future->is_pendingB= $self->is_pending
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 178 | weaken(my $invo_future = $self); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 79 | ▶ | $next_future->on_cancel(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 79 | ▶ | if(defined($invo_future) && $invo_future->is_pending) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $invo_future and $invo_future->is_pending
MC/DC50%1/2
defined $invo_future and $invo_future->is_pending
defined $invo_future
$invo_future->is_pending
Truth table66%2/3
A and B
A= defined $invo_futureB= $invo_future->is_pending
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | $invo_future->cancel(); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 178 | }); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 327 | return $next_future; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 51 | ▶ | sub catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
catch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 51 | my ($self, $on_rejected) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 51 | @_ = ($self, undef, $on_rejected); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 51 | goto $self->can('then'); | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 353 | ▶ | sub fulfill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fulfill: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 353 | goto $_[0]->can('done'); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 314 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 314 | my ($self, @result) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 314 | ▶ | if(not (@result == 1 && blessed($result[0]) && $result[0]->isa("Future"))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@result == 1 and builtin::blessed($result[0]) and $result[0]->isa("Future")
@result == 1 and builtin::blessed($result[0])
MC/DC66%2/3
@result == 1 and builtin::blessed($result[0]) and $result[0]->isa("Future")
@result == 1
builtin::blessed($result[0])
$result[0]->isa("Future")
Truth table75%3/4
A and B and C
A= @result == 1B= builtin::blessed($result[0])C= $result[0]->isa("Future")
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 7 | goto $self->can("fulfill"); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 307 | ▶ | return $self if $self->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 300 | my $base_future = $result[0]; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | ## Maybe we should check if $base_future is identical to | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ## $self. Promises/A+ spec v1.1 [1] states we should reject $self | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ## in that case. However, since Q v1.0.1 does not care that case, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ## we also leave that case unchecked for now. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 161 | ## [1]: https://github.com/promises-aplus/promises-spec/tree/1.1.0 | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 297 | ▶ | $base_future->on_ready(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 297 | my $base_future = shift; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 297 | ▶ | return if $self->is_ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 297 | ▶ | if($base_future->is_cancelled) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 53 | $self->cancel(); | |||||||||||||||||||||||||||||||||||||||||
| 168 | }elsif($base_future->failure) { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 102 | ▶ | if($base_future->can("_q_set_failure_handled")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 97 | $base_future->_q_set_failure_handled(); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 102 | $self->reject($base_future->failure); | |||||||||||||||||||||||||||||||||||||||||
| 173 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 142 | $self->fulfill($base_future->get); | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 300 | }); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 300 | ▶ | if(!$base_future->is_ready) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 76 | weaken(my $weak_base = $base_future); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 43 | ▶ | $self->on_cancel(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 43 | ▶ | $weak_base->cancel() if defined($weak_base) && !$weak_base->is_ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $weak_base and not $weak_base->is_ready
MC/DC50%1/2
defined $weak_base and not $weak_base->is_ready
defined $weak_base
not $weak_base->is_ready
Truth table66%2/3
A and not(B)
A= defined $weak_baseB= not $weak_base->is_ready
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 76 | }); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 300 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 257 | ▶ | sub reject { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reject: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 257 | goto $_[0]->can('fail'); | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1431 | ▶ | sub is_pending { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_pending: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 1431 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 1431 | return !$self->is_ready; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 281 | ▶ | sub is_fulfilled { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_fulfilled: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 281 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 281 | ▶ | return (!$self->is_pending && !$self->is_cancelled && !$self->is_rejected); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$self->is_pending || $self->is_cancelled || $self->is_rejected
$self->is_pending or $self->is_cancelled
MC/DC100%3/3
$self->is_pending || $self->is_cancelled || $self->is_rejected
$self->is_pending
$self->is_cancelled
$self->is_rejected
Truth table100%4/4
A or B || C
A= $self->is_pendingB= $self->is_cancelledC= $self->is_rejected
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 643 | ▶ | sub is_rejected { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_rejected: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 643 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 643 | ▶ | return ($self->is_ready && !!$self->failure); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->is_ready && !!$self->failure
MC/DC100%2/2
$self->is_ready && !!$self->failure
$self->is_ready
!!$self->failure
Truth table100%3/3
A && B
A= $self->is_readyB= !!$self->failure
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 20 | foreach my $method (qw(wait_all wait_any needs_all needs_any)) { | |||||||||||||||||||||||||||||||||||||||||
| 206 | 20 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 80 | my $supermethod_code = __PACKAGE__->can("SUPER::$method"); | |||||||||||||||||||||||||||||||||||||||||
| 208 | 80 | ▶ | *{$method} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 22 | my ($self, @subfutures) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 22 | foreach my $sub (@subfutures) { | |||||||||||||||||||||||||||||||||||||||||
| 211 | 99 | ▶ | next if !blessed($sub) || !$sub->can('_q_set_failure_handled'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($sub) and $sub->can("_q_set_failure_handled")
MC/DC0%0/2
builtin::blessed($sub) and $sub->can("_q_set_failure_handled")
builtin::blessed($sub)
$sub->can("_q_set_failure_handled")
Truth table33%1/3
A and B
A= builtin::blessed($sub)B= $sub->can("_q_set_failure_handled")
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 99 | $sub->_q_set_failure_handled(); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 22 | goto $supermethod_code; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 80 | }; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 53 | ▶ | sub finally { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finally: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 53 | my ($self, $callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 53 | my $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 53 | $self->_q_set_failure_handled(); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 53 | ▶ | if(!defined($callback) || ref($callback) ne "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $callback or ref $callback ne "CODE"
MC/DC0%0/2
not defined $callback or ref $callback ne "CODE"
not defined $callback
ref $callback ne "CODE"
Truth table33%1/3
not(A) or B
A= not defined $callbackB= ref $callback ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return $class->new->reject("Callback for finally() must be a code-ref"); | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 53 | my $next_future = $self->new; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 53 | ▶ | $self->on_ready(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 53 | my ($invo_future) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 53 | ▶ | if($invo_future->is_cancelled) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 17 | ▶ | $next_future->cancel if $next_future->is_pending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 36 | my $returned_future = $class->try($callback); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 36 | ▶ | $returned_future->on_ready(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | my ($returned_future) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 36 | ▶ | if(!$returned_future->is_cancelled && $returned_future->failure) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $returned_future->is_cancelled and $returned_future->failure
MC/DC100%2/2
not $returned_future->is_cancelled and $returned_future->failure
not $returned_future->is_cancelled
$returned_future->failure
Truth table100%3/3
not(A) and B
A= not $returned_future->is_cancelledB= $returned_future->failure
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 13 | $next_future->resolve($returned_future); | |||||||||||||||||||||||||||||||||||||||||
| 237 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 23 | $next_future->resolve($invo_future); | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 36 | }); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 36 | ▶ | if(!$returned_future->is_ready) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 16 | weaken(my $weak_returned = $returned_future); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | $next_future->on_cancel(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | $weak_returned->cancel if defined($weak_returned) && !$weak_returned->is_ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $weak_returned and not $weak_returned->is_ready
MC/DC0%0/2
defined $weak_returned and not $weak_returned->is_ready
defined $weak_returned
not $weak_returned->is_ready
Truth table33%1/3
A and not(B)
A= defined $weak_returnedB= not $weak_returned->is_ready
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 53 | }); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 53 | ▶ | if(!$self->is_ready) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 27 | weaken(my $weak_invo = $self); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 9 | ▶ | $next_future->on_cancel(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 9 | ▶ | $weak_invo->cancel if defined($weak_invo) && !$weak_invo->is_ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $weak_invo and not $weak_invo->is_ready
MC/DC50%1/2
defined $weak_invo and not $weak_invo->is_ready
defined $weak_invo
not $weak_invo->is_ready
Truth table66%2/3
A and not(B)
A= defined $weak_invoB= not $weak_invo->is_ready
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 27 | }); | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 53 | return $next_future; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | __END__ | ||||||||||||||||||||||||||||||||||||||||||