File Coverage

blib/lib/Promise/ES6/EventLoopBase.pm
Criterion Covered Total %
statement 9 36 25.0
branch 0 2 0.0
condition n/a
subroutine 3 11 27.2
pod 0 3 0.0
total 12 52 23.0


line stmt bran cond sub pod time code
1             package Promise::ES6::EventLoopBase;
2              
3 1     1   458 use strict;
  1         2  
  1         26  
4 1     1   6 use warnings;
  1         2  
  1         24  
5              
6 1     1   5 use parent qw(Promise::ES6);
  1         2  
  1         7  
7              
8             sub new {
9 0     0 0   my ($class, $cr) = @_;
10              
11             return $class->SUPER::new( sub {
12 0     0     my ($res, $rej) = @_;
13              
14 0           local $@;
15              
16 0           my $rej_pp = $class->_create_postpone_cb($rej);
17              
18 0           my $ok = eval {
19 0           $cr->(
20             $class->_create_postpone_cb($res),
21             $rej_pp,
22             );
23              
24 0           1;
25             };
26              
27 0 0         if (!$ok) {
28 0           $rej_pp->( my $err = $@ );
29             }
30 0           } );
31             }
32              
33             sub _create_postpone_cb {
34 0     0     my ($class, $cr) = @_;
35              
36             return sub {
37 0     0     my ($arg) = @_;
38 0           $class->_postpone( sub { $cr->($arg) } );
  0            
39             },
40 0           }
41              
42             sub then {
43 0     0 0   my ($self, $on_res, $on_rej) = @_;
44              
45 0           my $class = ref $self;
46              
47             return $class->new( sub {
48 0     0     my ($y, $n) = @_;
49              
50             $class->_postpone( sub {
51 0           $self->SUPER::then($on_res, $on_rej)->SUPER::then($y, $n);
52 0           } );
53 0           } );
54             }
55              
56             sub finally {
57 0     0 0   my ($self, $on_finish) = @_;
58              
59 0           my $class = ref $self;
60              
61             return $class->new( sub {
62 0     0     my ($y, $n) = @_;
63              
64             $class->_postpone( sub {
65 0           $self->SUPER::finally($on_finish)->SUPER::then($y, $n);
66 0           } );
67 0           } );
68             }
69              
70             1;