ES6/IOAsync.pm

filter: Statementstmt 52.3% 11 / 21 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 1 / 1 totaltotal 44.1% 15 / 34 CC 4 SCAR 17.7
CC
4
Cov
41%
SET_LOOP
12.0
_postpone
6.0
DESTROY
2.0
CRAP 5.9
« ES6/Backend/PP.pm ↑ Summary ES6/Event/IOAsync.pm »
1 package Promise::ES6::IOAsync;
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::IOAsync - L<Promises/A+-compliant|https://github.com/promises-aplus/promises-spec> promises for L<IO::Async>
11  
12 =head1 SYNOPSIS
13  
14 my $loop = IO::Async::Loop->new();
15  
16 my $loop_guard = Promise::ES6::IOAsync::SET_LOOP($loop);
17  
18 # Now use Promise::ES6::IOAsync as you would plain Promise::ES6.
19  
20 =head1 DEPRECATION NOTICE
21  
22 This module is deprecated and will go away eventually.
23 Use C<use_event()> instead, as described in L<Promise::ES6>’s documentation.
24  
25 =head1 DESCRIPTION
26  
27 This module exposes the same functionality as L<Promise::ES6::AnyEvent>
28 but for L<IO::Async> rather than L<AnyEvent>.
29  
30 Whereas L<AnyEvent> assumes that an event loop is global, L<IO::Async>
31 allows multiple concurrent event loops. In order to accommodate this
32 difference in architecture, this module requires an active L<IO::Async::Loop>
33 object before it can be used. See C<SET_LOOP()> below.
34  
35 =cut
36  
37 #----------------------------------------------------------------------
38  
39 1 ▶use parent qw(Promise::ES6::EventLoopBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 #----------------------------------------------------------------------
42  
43 1 my $LOOP;
44  
45 =head1 FUNCTIONS
46  
47 =head2 $guard = SET_LOOP( $LOOP )
48  
49 Sets this module’s active L<IO::Async::Loop> object. This is a internal
50 global; if you try to set a loop while one is already set, an exception
51 is thrown.
52  
53 This returns an opaque object that, when DESTROY()ed, will clear this
54 module’s internal loop.
55  
56 =cut
57  
58 0 ▶sub SET_LOOP {
Subroutine SET_LOOP: not called CC=3 SCAR=24.8
Pod documented
59 0 ▶ die "Loop is already set!" if $LOOP;
Branch: 1 branch
BranchTrueFalseTotal
if $LOOP 0 0 0
60  
61 0 ▶ if (!defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
62 0 my $fn = (caller 0)[3];
63 0 die "Void context to $fn() is useless!";
64 }
65  
66 0 $LOOP = $_[0];
67  
68 0 return bless [ \$LOOP ], 'Promise::ES6::IOAsync::_GUARD';
69 }
70  
71 0 ▶sub _postpone {
Subroutine _postpone: not called CC=2 SCAR=17.9
72 0 ▶ die "Need active loop … did you call SET_LOOP() first?" if !$LOOP;
Branch: 1 branch
BranchTrueFalseTotal
unless $LOOP 0 0 0
73  
74 0 return $LOOP->later( $_[1] );
75 }
76  
77 #----------------------------------------------------------------------
78  
79 package Promise::ES6::IOAsync::_GUARD;
80  
81 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
82 0 ${ $_[0][0] } = undef;
83 }
84  
85 1 1;
« ES6/Backend/PP.pm ↑ Summary ES6/Event/IOAsync.pm »