| 1 | package DBIO::Future::Immediate; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Dependency-free immediate Future for DBIO's 'immediate' async mode | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 39 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 39 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 39 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 39 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3241 | ▶ | sub done { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
done: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3241 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 3241 | bless { ready => 1, failed => 0, result => [@_] }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 96 | ▶ | sub fail { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 96 | my ($class, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 96 | bless { ready => 1, failed => 1, error => $error, result => [] }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1758 | ▶ | sub is_ready { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ready: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1381 | ▶ | sub is_failed { $_[0]->{failed} ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_failed: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 232 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 232 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 232 | ▶ | die $self->{error} if $self->{failed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 190 | ▶ | return wantarray ? @{ $self->{result} } : $self->{result}[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1723 | ▶ | sub then { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
then: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1723 | my ($self, $on_done, $on_fail) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1723 | ▶ | my $cb = $self->{failed} ? $on_fail : $on_done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 1723 | ▶ | return $self unless $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1709 | my @r = eval { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1709 | ▶ | $cb->($self->{failed} ? $self->{error} : @{ $self->{result} }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1709 | ▶ | return ref($self)->fail($@) if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1703 | ▶ | return $r[0] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
@r == 1 and builtin::blessed($r[0])
MC/DC66%2/3
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
@r == 1
builtin::blessed($r[0])
$r[0]->isa(__PACKAGE__)
Truth table75%3/4
A and B and C
A= @r == 1B= builtin::blessed($r[0])C= $r[0]->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | if @r == 1 && Scalar::Util::blessed($r[0]) && $r[0]->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 120 | return ref($self)->done(@r); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 20 | ▶ | sub catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
catch: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 20 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | return $self unless $self->{failed} and $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"failed"} and $cb
MC/DC100%2/2
$self->{"failed"} and $cb
$self->{"failed"}
$cb
Truth table100%3/3
A and B
A= $self->{"failed"}B= $cb
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 18 | my @r = eval { $cb->($self->{error}) }; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 18 | ▶ | return ref($self)->fail($@) if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 18 | ▶ | return $r[0] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
@r == 1 and builtin::blessed($r[0])
MC/DC66%2/3
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
@r == 1
builtin::blessed($r[0])
$r[0]->isa(__PACKAGE__)
Truth table75%3/4
A and B and C
A= @r == 1B= builtin::blessed($r[0])C= $r[0]->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | if @r == 1 && Scalar::Util::blessed($r[0]) && $r[0]->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | return ref($self)->done(@r); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub and_then { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
and_then: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | return $self if $self->{failed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my $inner = eval { $cb->(@{ $self->{result} }) }; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | return ref($self)->fail($@) if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | return $inner if ref($inner) && $inner->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $inner and $inner->isa(__PACKAGE__)
MC/DC0%0/2
ref $inner and $inner->isa(__PACKAGE__)
ref $inner
$inner->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= ref $innerB= $inner->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return ref($self)->done($inner); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | sub needs_all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
needs_all: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | my ($class, @futures) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | for my $f (@futures) { | |||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | return $f if $f->is_failed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | push @results, $f->get; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return $class->done(@results); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 39 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||||||||||||