Promises/Utils.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 3 totaltotal 84.3% 54 / 64 CC 4 SCAR 4.3
CC
4
Cov
91%
__ANON__
3.1
then
2.0
__ANON__
2.0
CRAP 1.5
« Promises.pm ↑ Summary
1 package fs::Promises::Utils;
2 2 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use AnyEvent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use AnyEvent::XSPromises ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 our @EXPORT_OK = qw(await p_while then);
9  
10 10 ▶sub await ($) {
Subroutine await: called CC=1 SCAR=0.0
Pod undocumented
11 10 my $p = shift;
12 10 my $cv = AnyEvent->condvar;
13 $p->then(
14 7 ▶ sub { $cv->send(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 3 ▶ sub { $cv->croak(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 10 );
17 10 return $cv->recv;
18 }
19  
20 0 ▶sub then (&) { return $_[0] }
Subroutine then: not called CC=1 SCAR=6.9
Pod undocumented
21 1 ▶sub p_while (&$) {
Subroutine p_while: called CC=1 SCAR=0.0
Pod undocumented
22 1 my ($while_cond, $cb) = @_;
23  
24 1 my $d = AnyEvent::XSPromises::deferred();
25  
26 86 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
27 86 my $do_while = __SUB__;
28 86 my $cond = $while_cond->();
29 86 ▶ $cond = AnyEvent::XSPromises::resolved($cond) if !blessed($cond) || !$cond->can('then');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($cond) and $cond->can("then") 0 86 86
Condition33%1/3
builtin::blessed($cond) and $cond->can("then")
!ll&&!rl&&r
0086
MC/DC0%0/2
builtin::blessed($cond) and $cond->can("then")
builtin::blessed($cond) $cond->can("then")
Truth table33%1/3
A and B
A= builtin::blessed($cond)B= $cond->can("then")
ABresult
0X0
100
111
30 86 ▶ return $cond->then(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
31 86 ▶ return unless defined($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 1 85 86
32 85 $cb->($_[0]);
33 85 $do_while->();
34 })
35 1 ▶ }->()->finally(sub { $d->resolve });
Subroutine __ANON__: called CC=1 SCAR=0.0
36  
37 1 return $d->promise;
38 }
39  
40 2 1;
41  
« Promises.pm ↑ Summary