ES6/Backend/PP.pm

filter: Statementstmt 53.0% 165 / 311 Branchbran 43.3% 59 / 136 Conditioncond 31.4% 17 / 54 MC/DCmcdc 20.0% 6 / 30 Subroutinesub 53.8% 28 / 52 Podpod 0.0% 0 / 22 totaltotal 45.4% 275 / 605 CC 97 SCAR 31.3
CC
97
Cov
48%
_settle_now
65.8
_settle_now
65.8
DESTROY
27.0
CRAP 22.9
↑ Summary ES6/IOAsync.pm »
1 package Promise::ES6;
2  
3 #----------------------------------------------------------------------
4 # This module iS NOT a defined interface. Nothing to see here …
5 #----------------------------------------------------------------------
6  
7 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 42 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 42 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # These aren’t actually defined.
15 42 _RESOLUTION_CLASS => 'Promise::ES6::_RESOLUTION',
16 _REJECTION_CLASS => 'Promise::ES6::_REJECTION',
17 _PENDING_CLASS => 'Promise::ES6::_PENDING',
18  
19 _DEBUG => 0,
20 42 };
21  
22 42 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 42 _PROMISE_ID_IDX => 0,
24 _PID_IDX => _DEBUG + 0,
25 _CHILDREN_IDX => _DEBUG + 1,
26 _VALUE_SR_IDX => _DEBUG + 2,
27 _DETECT_LEAK_IDX => _DEBUG + 3,
28 _ON_RESOLVE_IDX => _DEBUG + 4,
29 _ON_REJECT_IDX => _DEBUG + 5,
30 _IS_FINALLY_IDX => _DEBUG + 6,
31  
32 # For async/await:
33 _ON_READY_IMMEDIATE_IDX => _DEBUG + 7,
34 _SELF_REF_IDX => _DEBUG + 8,
35 42 };
36  
37 # "$value_sr" => $value_sr
38 42 our %_UNHANDLED_REJECTIONS;
39  
40 42 my $_debug_promise_id = 0;
41 0 ▶sub _create_promise_id { return $_debug_promise_id++ . "-$_[0]" }
Subroutine _create_promise_id: not called CC=1 SCAR=6.9
42  
43 139 ▶sub new {
Subroutine new: called CC=3 SCAR=14.6
Pod undocumented
44 0 ▶ my ( $class, $cr ) = @_;
Subroutine new: not called CC=3 SCAR=14.6
Pod undocumented
45  
46 0 ▶ die 'Need callback!' if !$cr;
Branch: 2 branches
BranchTrueFalseTotal
unless $cr 0 139 139
unless $cr 0 0 0
47  
48 0 my $value;
49 0 my $value_sr = bless \$value, _PENDING_CLASS();
50  
51 0 my @children;
52  
53 0 my $self = bless [
54 ( _DEBUG ? undef : () ),
55 $$,
56 \@children,
57 $value_sr,
58 $Promise::ES6::DETECT_MEMORY_LEAKS,
59 ], $class;
60  
61 0 $self->[_PROMISE_ID_IDX] = _create_promise_id($self) if _DEBUG;
62  
63 # NB: These MUST NOT refer to $self, or else we can get memory leaks
64 # depending on how $resolver and $rejector are used.
65 59 ▶ my $resolver = sub {
Subroutine __ANON__: called CC=5 SCAR=21.8
66 0 ▶ $$value_sr = $_[0];
Subroutine __ANON__: not called CC=5 SCAR=21.8
67  
68 # NB: UNIVERSAL::can() is used in order to avoid an eval {}.
69 # It is acknowledged that many Perl experts strongly discourage
70 # use of this technique.
71 0 ▶ if ( UNIVERSAL::can( $$value_sr, 'then' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::can($$value_sr, "then")) 2 57 59
if (UNIVERSAL::can($$value_sr, "then")) 0 0 0
72 0 return _repromise( $value_sr, \@children, $value_sr );
73 }
74  
75 0 bless $value_sr, _RESOLUTION_CLASS();
76  
77 0 ▶ $self->[_ON_READY_IMMEDIATE_IDX]->() if $self->[_ON_READY_IMMEDIATE_IDX];
Branch: 2 branches
BranchTrueFalseTotal
if $self->[7] 0 57 57
if $self->[7] 0 0 0
78  
79 0 undef $self->[_SELF_REF_IDX];
80  
81 0 ▶ if (@children) {
Branch: 2 branches
BranchTrueFalseTotal
if (@children) 17 40 57
if (@children) 0 0 0
82 0 $_->_settle($value_sr) for splice @children;
83 }
84 0 };
85  
86 44 ▶ my $rejecter = sub {
Subroutine __ANON__: called CC=6 SCAR=24.1
87 0 ▶ if (!defined $_[0]) {
Subroutine __ANON__: not called CC=6 SCAR=24.1
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $_[0]) 4 40 44
unless (defined $_[0]) 0 0 0
88 0 my $msg;
89  
90 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 3 1 4
if (@_) { } 0 0 0
91 0 $msg = "$class: Uninitialized rejection value given";
92 }
93 else {
94 0 $msg = "$class: No rejection value given";
95 }
96  
97 0 Carp::carp($msg);
98 }
99  
100 0 $$value_sr = $_[0];
101 0 bless $value_sr, _REJECTION_CLASS();
102  
103 0 $_UNHANDLED_REJECTIONS{$value_sr} = $value_sr;
104  
105 0 ▶ $self->[_ON_READY_IMMEDIATE_IDX]->() if $self->[_ON_READY_IMMEDIATE_IDX];
Branch: 2 branches
BranchTrueFalseTotal
if $self->[7] 0 44 44
if $self->[7] 0 0 0
106  
107 0 undef $self->[_SELF_REF_IDX];
108  
109 # We do not repromise rejections. Whatever is in $$value_sr
110 # is literally what rejection callbacks receive.
111 0 ▶ if (@children) {
Branch: 2 branches
BranchTrueFalseTotal
if (@children) 8 36 44
if (@children) 0 0 0
112 0 $_->_settle($value_sr) for splice @children;
113 }
114 0 };
115  
116 0 local $@;
117 0 ▶ if ( !eval { $cr->( $resolver, $rejecter ); 1 } ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (eval { do { &$cr($resolver, $rejecter); 1 } }) 9 130 139
unless (eval { do { &$cr($resolver, $rejecter); 1 } }) 0 0 0
118 0 $$value_sr = $@;
119 0 bless $value_sr, _REJECTION_CLASS();
120  
121 0 $_UNHANDLED_REJECTIONS{$value_sr} = $value_sr;
122 }
123  
124 0 return $self;
125 }
126  
127 130 ▶sub then {
Subroutine then: called CC=1 SCAR=1.2
Pod undocumented
128 0 ▶ return $_[0]->_then_or_finally(@_[1, 2]);
Subroutine then: not called CC=1 SCAR=1.2
Pod undocumented
129 }
130  
131 13 ▶sub finally {
Subroutine finally: called CC=2 SCAR=10.9
Pod undocumented
132  
133 # There’s no reason to call finally() without a callback
134 # since it would just be a no-op.
135 0 ▶ die 'finally() requires a callback!' if !$_[1];
Subroutine finally: not called CC=2 SCAR=10.9
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
unless $_[1] 0 13 13
unless $_[1] 0 0 0
136  
137 0 return $_[0]->_then_or_finally($_[1], undef, 1);
138 }
139  
140 143 ▶sub _then_or_finally {
Subroutine _then_or_finally: called CC=2 SCAR=9.2
141 0 ▶ my ($self, $on_resolve_or_finish, $on_reject, $is_finally) = @_;
Subroutine _then_or_finally: not called CC=2 SCAR=9.2
142  
143 0 my $value_sr = bless( \do { my $v }, _PENDING_CLASS() );
144  
145 0 my $new = bless [
146 ( _DEBUG ? undef : () ),
147 $$,
148 [],
149 $value_sr,
150 $Promise::ES6::DETECT_MEMORY_LEAKS,
151 $on_resolve_or_finish,
152 $on_reject,
153 $is_finally,
154 ],
155 ref($self);
156  
157 0 $new->[_PROMISE_ID_IDX] = _create_promise_id($new) if _DEBUG;
158  
159 0 ▶ if ( _PENDING_CLASS eq ref $self->[_VALUE_SR_IDX] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('Promise::ES6::_PENDING' eq ref $self->[2]) { } 46 97 143
if ('Promise::ES6::_PENDING' eq ref $self->[2]) { } 0 0 0
160 0 push @{ $self->[_CHILDREN_IDX] }, $new;
161 }
162 else {
163  
164 # $self might already be settled, in which case we immediately
165 # settle the $new promise as well.
166  
167 0 $new->_settle( $self->[_VALUE_SR_IDX] );
168 }
169  
170 0 return $new;
171 }
172  
173 10 ▶sub _repromise {
Subroutine _repromise: called CC=1 SCAR=1.2
174 0 ▶ my ( $value_sr, $children_ar, $repromise_value_sr, $orig_finally_sr ) = @_;
Subroutine _repromise: not called CC=1 SCAR=1.2
175 $$repromise_value_sr->then(
176 6 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
177 0 ▶ if (ref $orig_finally_sr) {
Subroutine __ANON__: not called CC=3 SCAR=14.2
Branch: 2 branches
BranchTrueFalseTotal
if (ref $orig_finally_sr) { } 1 5 6
if (ref $orig_finally_sr) { } 0 0 0
178 0 $$value_sr = $$orig_finally_sr;
179 }
180 else {
181 0 $$value_sr = $_[0];
182 }
183  
184 0 bless $value_sr, _RESOLUTION_CLASS;
185 0 $_->_settle($value_sr) for splice @$children_ar;
186 },
187 4 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
188 0 ▶ $$value_sr = $_[0];
Subroutine __ANON__: not called CC=2 SCAR=9.2
189 0 bless $value_sr, _REJECTION_CLASS;
190 0 $_UNHANDLED_REJECTIONS{$value_sr} = $value_sr;
191 0 $_->_settle($value_sr) for splice @$children_ar;
192 },
193 0 );
194 0 return;
195  
196 }
197  
198 # It’s gainfully faster to inline this:
199 #sub _is_completed {
200 # return (_PENDING_CLASS ne ref $_[0][ _VALUE_SR_IDX ]);
201 #}
202  
203 # This method *only* runs to “settle” a promise.
204 133 ▶sub _settle {
Subroutine _settle: called CC=4 SCAR=21.1
205 0 ▶ my ( $self, $final_value_sr ) = @_;
Subroutine _settle: not called CC=4 SCAR=21.1
206  
207 0 ▶ die "$self already settled!" if _PENDING_CLASS ne ref $self->[_VALUE_SR_IDX];
Branch: 2 branches
BranchTrueFalseTotal
if "Promise::ES6::_PENDING" ne ref $self->[2] 0 133 133
if "Promise::ES6::_PENDING" ne ref $self->[2] 0 0 0
208  
209 0 my $settle_is_rejection = _REJECTION_CLASS eq ref $final_value_sr;
210  
211 # This has to happen up-front or else we can get spurious
212 # unhandled-rejection warnings in asynchronous mode.
213 0 ▶ delete $_UNHANDLED_REJECTIONS{$final_value_sr} if $settle_is_rejection;
Branch: 2 branches
BranchTrueFalseTotal
if $settle_is_rejection 57 76 133
if $settle_is_rejection 0 0 0
214  
215 0 ▶ if ($Promise::ES6::_EVENT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Promise::ES6::_EVENT) { } 0 133 133
if ($Promise::ES6::_EVENT) { } 0 0 0
216 0 ▶ _postpone( sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
217 0 ▶ $self->_settle_now($final_value_sr, $settle_is_rejection);
Subroutine __ANON__: not called CC=1 SCAR=6.9
218 0 } );
219 }
220 else {
221 0 $self->_settle_now($final_value_sr, $settle_is_rejection);
222 }
223 }
224  
225 139 ▶sub _settle_now {
Subroutine _settle_now: called CC=19 SCAR=41.9
226 0 ▶ my ( $self, $final_value_sr, $settle_is_rejection ) = @_;
Subroutine _settle_now: not called CC=19 SCAR=41.9
227  
228 0 my $self_is_finally = $self->[_IS_FINALLY_IDX];
229  
230 # A promise that new() created won’t have on-settle callbacks,
231 # but a promise that came from then/catch/finally will.
232 # It’s a good idea to delete the callbacks in order to trigger garbage
233 # collection as soon and as reliably as possible. It’s safe to do so
234 # because _settle() is only called once.
235 0 ▶ my $callback = $self->[ ($settle_is_rejection && !$self_is_finally) ? _ON_REJECT_IDX : _ON_RESOLVE_IDX ];
Branch: 2 branches
BranchTrueFalseTotal
$settle_is_rejection && !$self_is_finally ? : 53 86 139
$settle_is_rejection && !$self_is_finally ? : 0 0 0
Condition50%3/6
$settle_is_rejection and not $self_is_finally
!ll&&!rl&&r
80653
$settle_is_rejection and not $self_is_finally
!ll&&!rl&&r
000
MC/DC100%2/2
$settle_is_rejection and not $self_is_finally
$settle_is_rejection not $self_is_finally
MC/DC0%0/2
$settle_is_rejection and not $self_is_finally
$settle_is_rejection not $self_is_finally
Truth table100%3/3
A and not(B)
A= $settle_is_rejectionB= not $self_is_finally
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $settle_is_rejectionB= not $self_is_finally
ABresult
0X0
100
111
236  
237 0 @{$self}[ _ON_RESOLVE_IDX, _ON_REJECT_IDX ] = ();
238  
239 # In some contexts this function runs quite a lot,
240 # so caching the is-promise lookup is useful.
241 0 my $value_sr_contents_is_promise = 1;
242  
243 0 ▶ if ($callback) {
Branch: 2 branches
BranchTrueFalseTotal
if ($callback) { } 130 9 139
if ($callback) { } 0 0 0
244  
245 # This is the block that runs for promises that were created by a
246 # call to then() that assigned a handler for the state that
247 # $final_value_sr indicates (i.e., resolved or rejected).
248  
249 0 my ($new_value, $callback_failed);
250  
251 0 local $@;
252  
253 0 ▶ if ( eval { $new_value = $callback->($self_is_finally ? () : $$final_value_sr); 1 } ) {
Branch: 4 branches
BranchTrueFalseTotal
if (eval { do { $new_value = &$callback($self_is_finally ? () : $$final_value_sr); 1 } }) { } 127 3 130
$self_is_finally ? : 12 118 130
if (eval { do { $new_value = &$callback($self_is_finally ? () : $$final_value_sr); 1 } }) { } 0 0 0
$self_is_finally ? : 0 0 0
254  
255 # The callback succeeded. If $new_value is not itself a promise,
256 # then $self is now resolved. (Yay!) Note that this is true
257 # even if $final_value_sr indicates a rejection: in this case, we’ve
258 # just run a successful “catch” block, so resolution is correct.
259  
260 # If $new_value IS a promise, though, then we have to wait.
261 0 ▶ if ( !UNIVERSAL::can( $new_value, 'then' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (UNIVERSAL::can($new_value, "then")) 119 8 127
unless (UNIVERSAL::can($new_value, "then")) 0 0 0
262 0 $value_sr_contents_is_promise = 0;
263  
264 0 ▶ if ($self_is_finally) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self_is_finally) { } 8 111 119
if ($self_is_finally) { } 0 0 0
265  
266 # finally() is a bit weird. Assuming its callback succeeds,
267 # it takes its parent’s resolution state. It’s important
268 # that we make a *new* reference to the resolution value,
269 # though, rather than merely using $final_value_sr itself,
270 # because we need $self to have its own entry in
271 # %_UNHANDLED_REJECTIONS.
272 0 ${ $self->[_VALUE_SR_IDX] } = $$final_value_sr;
273 0 bless $self->[_VALUE_SR_IDX], ref $final_value_sr;
274  
275 0 ▶ $_UNHANDLED_REJECTIONS{ $self->[_VALUE_SR_IDX] } = $self->[_VALUE_SR_IDX] if $settle_is_rejection;
Branch: 2 branches
BranchTrueFalseTotal
if $settle_is_rejection 6 2 8
if $settle_is_rejection 0 0 0
276 }
277 else {
278 0 bless $self->[_VALUE_SR_IDX], _RESOLUTION_CLASS;
279 }
280 }
281 }
282 else {
283 0 $callback_failed = 1;
284  
285 # The callback errored, which means $self is now rejected.
286  
287 0 $new_value = $@;
288 0 $value_sr_contents_is_promise = 0;
289  
290 0 bless $self->[_VALUE_SR_IDX], _REJECTION_CLASS();
291 0 $_UNHANDLED_REJECTIONS{ $self->[_VALUE_SR_IDX] } = $self->[_VALUE_SR_IDX];
292 }
293  
294 0 ▶ if (!$self_is_finally || $value_sr_contents_is_promise || ($self_is_finally && $callback_failed)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self_is_finally or $value_sr_contents_is_promise or $self_is_finally and $callback_failed) 122 8 130
if (not $self_is_finally or $value_sr_contents_is_promise or $self_is_finally and $callback_failed) 0 0 0
Condition44%8/18
not $self_is_finally or $value_sr_contents_is_promise or $self_is_finally and $callback_failed
l!l&&r!l&&!r
12118
not $self_is_finally or $value_sr_contents_is_promise
l!l&&r!l&&!r
11839
$self_is_finally and $callback_failed
!ll&&!rl&&r
081
not $self_is_finally or $value_sr_contents_is_promise or $self_is_finally and $callback_failed
l!l&&r!l&&!r
000
not $self_is_finally or $value_sr_contents_is_promise
l!l&&r!l&&!r
000
$self_is_finally and $callback_failed
!ll&&!rl&&r
000
MC/DC75%3/4
not $self_is_finally or $value_sr_contents_is_promise or $self_is_finally and $callback_failed
not $self_is_finally $value_sr_contents_is_promise $self_is_finally $callback_failed
MC/DC0%0/4
not $self_is_finally or $value_sr_contents_is_promise or $self_is_finally and $callback_failed
not $self_is_finally $value_sr_contents_is_promise $self_is_finally $callback_failed
Truth table80%4/5
not(A) or B or C and D
A= not $self_is_finallyB= $value_sr_contents_is_promiseC= $self_is_finallyD= $callback_failed
ABCDresult
1XXX1
01XX1
00111
000X0
00100
Truth table0%0/5
not(A) or B or C and D
A= not $self_is_finallyB= $value_sr_contents_is_promiseC= $self_is_finallyD= $callback_failed
ABCDresult
1XXX1
01XX1
00111
000X0
00100
295 0 ${ $self->[_VALUE_SR_IDX] } = $new_value;
296 }
297 }
298 else {
299  
300 # There was no handler from then(), so whatever state $final_value_sr
301 # indicates # (i.e., resolution or rejection) is now $self’s state
302 # as well.
303  
304 # NB: We should NEVER be here if the promise is from finally().
305  
306 0 bless $self->[_VALUE_SR_IDX], ref($final_value_sr);
307 0 ${ $self->[_VALUE_SR_IDX] } = $$final_value_sr;
308 0 $value_sr_contents_is_promise = UNIVERSAL::can( $$final_value_sr, 'then' );
309  
310 0 ▶ if ($settle_is_rejection) {
Branch: 2 branches
BranchTrueFalseTotal
if ($settle_is_rejection) 4 5 9
if ($settle_is_rejection) 0 0 0
311 0 $_UNHANDLED_REJECTIONS{ $self->[_VALUE_SR_IDX] } = $self->[_VALUE_SR_IDX];
312 }
313 }
314  
315 0 ▶ if ($value_sr_contents_is_promise) {
Branch: 4 branches
BranchTrueFalseTotal
if ($value_sr_contents_is_promise) { } 8 131 139
elsif (@{$self->[1];}) { } 2 129 131
if ($value_sr_contents_is_promise) { } 0 0 0
elsif (@{$self->[1];}) { } 0 0 0
316  
317 # Stash the given concrete value. If the $value_sr promise
318 # rejects, then we’ll accept that, but if it resolves, then
319 # we’ll look at this to know to discard that resolution.
320 0 ▶ if ($self_is_finally) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self_is_finally) 3 5 8
if ($self_is_finally) 0 0 0
321 0 $self->[_IS_FINALLY_IDX] = $final_value_sr;
322 }
323  
324 0 return _repromise( @{$self}[ _VALUE_SR_IDX, _CHILDREN_IDX, _VALUE_SR_IDX, _IS_FINALLY_IDX ] );
325 }
326 0 elsif ( @{ $self->[_CHILDREN_IDX] } ) {
327 0 $_->_settle( $self->[_VALUE_SR_IDX] ) for splice @{ $self->[_CHILDREN_IDX] };
328 }
329  
330 0 ▶ $self->[_ON_READY_IMMEDIATE_IDX]->() if $self->[_ON_READY_IMMEDIATE_IDX];
Branch: 2 branches
BranchTrueFalseTotal
if $self->[7] 2 129 131
if $self->[7] 0 0 0
331  
332 0 undef $self->[_SELF_REF_IDX];
333  
334 0 return;
335 }
336  
337 261 ▶sub DESTROY {
Subroutine DESTROY: called CC=8 SCAR=32.9
338  
339 # The PID should always be there, but this accommodates mocks.
340 0 ▶ return unless $_[0][_PID_IDX] && $$ == $_[0][_PID_IDX];
Subroutine DESTROY: not called CC=8 SCAR=32.9
Branch: 2 branches
BranchTrueFalseTotal
unless $_[0][0] and $$ == $_[0][0] 2 259 261
unless $_[0][0] and $$ == $_[0][0] 0 0 0
Condition33%2/6
$_[0][0] and $$ == $_[0][0]
!ll&&!rl&&r
02259
$_[0][0] and $$ == $_[0][0]
!ll&&!rl&&r
000
MC/DC50%1/2
$_[0][0] and $$ == $_[0][0]
$_[0][0] $$ == $_[0][0]
MC/DC0%0/2
$_[0][0] and $$ == $_[0][0]
$_[0][0] $$ == $_[0][0]
Truth table66%2/3
A and B
A= $_[0][0]B= $$ == $_[0][0]
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $_[0][0]B= $$ == $_[0][0]
ABresult
0X0
100
111
341  
342 0 ▶ if ( $_[0][_DETECT_LEAK_IDX] && ${^GLOBAL_PHASE} && ${^GLOBAL_PHASE} eq 'DESTRUCT' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0][3] and ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT") 0 259 259
if ($_[0][3] and ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT") 0 0 0
Condition16%2/12
$_[0][3] and ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
!ll&&!rl&&r
25900
$_[0][3] and ${^GLOBAL_PHASE}
!ll&&!rl&&r
25900
$_[0][3] and ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
!ll&&!rl&&r
000
$_[0][3] and ${^GLOBAL_PHASE}
!ll&&!rl&&r
000
MC/DC0%0/3
$_[0][3] and ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
$_[0][3] ${^GLOBAL_PHASE} ${^GLOBAL_PHASE} eq "DESTRUCT"
MC/DC0%0/3
$_[0][3] and ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
$_[0][3] ${^GLOBAL_PHASE} ${^GLOBAL_PHASE} eq "DESTRUCT"
Truth table25%1/4
A and B and C
A= $_[0][3]B= ${^GLOBAL_PHASE}C= ${^GLOBAL_PHASE} eq "DESTRUCT"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $_[0][3]B= ${^GLOBAL_PHASE}C= ${^GLOBAL_PHASE} eq "DESTRUCT"
ABCresult
0XX0
10X0
1100
1111
343 0 warn( ( '=' x 70 ) . "\n" . 'XXXXXX - ' . ref( $_[0] ) . " survived until global destruction; memory leak likely!\n" . ( "=" x 70 ) . "\n" );
344 }
345  
346 0 ▶ if ( defined $_[0][_VALUE_SR_IDX] ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0][2]) 259 0 259
if (defined $_[0][2]) 0 0 0
347 0 my $promise_value_sr = $_[0][_VALUE_SR_IDX];
348 0 ▶ if ( my $value_sr = delete $_UNHANDLED_REJECTIONS{$promise_value_sr} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $value_sr = delete $Promise::ES6::_UNHANDLED_REJECTIONS{$promise_value_sr}) 13 246 259
if (my $value_sr = delete $Promise::ES6::_UNHANDLED_REJECTIONS{$promise_value_sr}) 0 0 0
349 0 warn "$_[0]: Unhandled rejection: $$value_sr";
350 }
351 }
352 }
353  
354 #----------------------------------------------------------------------
355  
356 # Future::AsyncAwait::Awaitable interface:
357  
358 # Future::AsyncAwait doesn’t retain a strong reference to its created
359 # promises, as a result of which we need to create a self-reference
360 # inside the promise. We’ll clear that self-reference once the promise
361 # is finished, which avoids memory leaks.
362 #
363 8 ▶sub _immortalize {
Subroutine _immortalize: called CC=1 SCAR=1.2
364 0 ▶ my $method = $_[0];
Subroutine _immortalize: not called CC=1 SCAR=1.2
365  
366 0 my $new = $_[1]->$method(@_[2 .. $#_]);
367  
368 0 $new->[_SELF_REF_IDX] = $new;
369 }
370  
371 2 ▶sub AWAIT_NEW_DONE {
Subroutine AWAIT_NEW_DONE: called CC=2 SCAR=13.0
Pod undocumented
372 0 ▶ _immortalize('resolve', (ref($_[0]) || $_[0]), $_[1]);
Subroutine AWAIT_NEW_DONE: not called CC=2 SCAR=13.0
Pod undocumented
Condition16%1/6
ref $_[0] || $_[0]
l!l&&r!l&&!r
020
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
373 }
374  
375 2 ▶sub AWAIT_NEW_FAIL {
Subroutine AWAIT_NEW_FAIL: called CC=2 SCAR=13.0
Pod undocumented
376 0 ▶ _immortalize('reject', (ref($_[0]) || $_[0]), $_[1]);
Subroutine AWAIT_NEW_FAIL: not called CC=2 SCAR=13.0
Pod undocumented
Condition16%1/6
ref $_[0] || $_[0]
l!l&&r!l&&!r
020
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
377 }
378  
379 4 ▶sub AWAIT_CLONE {
Subroutine AWAIT_CLONE: called CC=1 SCAR=1.2
Pod undocumented
380 0 ▶ _immortalize('new', ref($_[0]), \&_noop);
Subroutine AWAIT_CLONE: not called CC=1 SCAR=1.2
Pod undocumented
381 }
382  
383 4 ▶sub AWAIT_DONE {
Subroutine AWAIT_DONE: called CC=1 SCAR=1.2
Pod undocumented
384 0 ▶ my $copy = $_[1];
Subroutine AWAIT_DONE: not called CC=1 SCAR=1.2
Pod undocumented
385  
386 0 $_[0]->_settle_now(bless \$copy, _RESOLUTION_CLASS);
387 }
388  
389 2 ▶sub AWAIT_FAIL {
Subroutine AWAIT_FAIL: called CC=1 SCAR=1.2
Pod undocumented
390 0 ▶ my $copy = $_[1];
Subroutine AWAIT_FAIL: not called CC=1 SCAR=1.2
Pod undocumented
391  
392 0 $_[0]->_settle_now(bless(\$copy, _REJECTION_CLASS), 1);
393 }
394  
395 12 ▶sub AWAIT_IS_READY {
Subroutine AWAIT_IS_READY: called CC=1 SCAR=1.2
Pod undocumented
396 0 ▶ !UNIVERSAL::isa( $_[0]->[_VALUE_SR_IDX], _PENDING_CLASS );
Subroutine AWAIT_IS_READY: not called CC=1 SCAR=1.2
Pod undocumented
397 }
398  
399 42 ▶use constant AWAIT_IS_CANCELLED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
400  
401 12 ▶sub AWAIT_GET {
Subroutine AWAIT_GET: called CC=3 SCAR=15.0
Pod undocumented
402 0 ▶ delete $_UNHANDLED_REJECTIONS{$_[0]->[_VALUE_SR_IDX]};
Subroutine AWAIT_GET: not called CC=3 SCAR=15.0
Pod undocumented
403  
404 0 ▶ return ${ $_[0]->[_VALUE_SR_IDX] } if UNIVERSAL::isa( $_[0]->[_VALUE_SR_IDX], _RESOLUTION_CLASS );
Branch: 2 branches
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0][2], "Promise::ES6::_RESOLUTION") 8 4 12
if UNIVERSAL::isa($_[0][2], "Promise::ES6::_RESOLUTION") 0 0 0
405  
406 0 my $err = ${ $_[0]->[_VALUE_SR_IDX] };
407 0 ▶ die $err if substr($err, -1) eq "\n";
Branch: 2 branches
BranchTrueFalseTotal
if substr($err, -1) eq "\n" 0 4 4
if substr($err, -1) eq "\n" 0 0 0
408 0 Carp::croak $err;
409 }
410  
411 42 ▶use constant _noop => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
412  
413 2 ▶sub AWAIT_ON_READY {
Subroutine AWAIT_ON_READY: called CC=1 SCAR=1.2
Pod undocumented
414 0 ▶ $_[0][_ON_READY_IMMEDIATE_IDX] = $_[1];
Subroutine AWAIT_ON_READY: not called CC=1 SCAR=1.2
Pod undocumented
415 }
416  
417 42 *AWAIT_CHAIN_CANCEL = *_noop;
418 42 *AWAIT_ON_CANCEL = *_noop;
419  
420 42 1;
↑ Summary ES6/IOAsync.pm »