blib/lib/Text/Nunjucks/EmitterObj.pm

filter: Statementstmt 67.8% 19 / 28 Branchbran 50.0% 2 / 4 Conditioncond 30.0% 3 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 71.4% 5 / 7 Podpod 100% 4 / 4 totaltotal 57.6% 34 / 59 CC 9 SCAR 15.0
CC
9
Cov
57%
emit
6.7
emit
6.7
on
2.8
CRAP 4.5
« blib/lib/Text/Nunjucks/Runtime/Frame.pm ↑ Summary blib/lib/Text/Nunjucks/Globals.pm »
1 package Text::Nunjucks::EmitterObj;
2 # ABSTRACT: the on/emit surface of src/object.js EmitterObj, as a Moo role (ADR 0002)
3  
4 15 our $VERSION = '0.001';
5  
6 15 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # object.js's EmitterObj extends node's EventEmitter; ADR 0002 replaces it with
10 # "a small role with on/emit". Only the subset the engine uses is modelled:
11 # Loader concrete subclasses emit('update'|'load', ...) and Environment listens
12 # via loader.on(...) and re-emits to its own listeners. No once/removeListener/
13 # error-event semantics are needed by the port, so none are provided.
14  
15 10272 ▶has _listeners => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
16  
17 # emitter.on(event, listener) -- register a listener, return the emitter.
18 10244 ▶sub on {
Subroutine on: called CC=2 SCAR=10.3
Pod documented
19 0 ▶ my ( $self, $event, $listener ) = @_;
Subroutine on: not called CC=2 SCAR=10.3
Pod documented
20 0 ▶ push @{ $self->_listeners->{$event} //= [] }, $listener;
Condition25%1/4
$self->_listeners->{$event} //= []
l!l
010244
$self->_listeners->{$event} //= []
l!l
00
MC/DC0%0/1
$self->_listeners->{$event} //= []
$self->_listeners->{$event}
MC/DC0%0/1
$self->_listeners->{$event} //= []
$self->_listeners->{$event}
Truth table50%1/2
A
A= $self->_listeners->{$event}
Aresult
11
00
Truth table0%0/2
A
A= $self->_listeners->{$event}
Aresult
11
00
21 0 return $self;
22 }
23  
24 # emitter.emit(event, ...args) -- call every listener in registration order.
25 247 ▶sub emit {
Subroutine emit: called CC=4 SCAR=19.0
Pod documented
26 0 ▶ my ( $self, $event, @args ) = @_;
Subroutine emit: not called CC=4 SCAR=19.0
Pod documented
27 0 my $listeners = $self->_listeners->{$event};
28 0 ▶ return 0 unless $listeners && @$listeners;
Branch: 2 branches
BranchTrueFalseTotal
unless $listeners and @$listeners 115 132 247
unless $listeners and @$listeners 0 0 0
Condition33%2/6
$listeners and @$listeners
!ll&&!rl&&r
1150132
$listeners and @$listeners
!ll&&!rl&&r
000
MC/DC50%1/2
$listeners and @$listeners
$listeners @$listeners
MC/DC0%0/2
$listeners and @$listeners
$listeners @$listeners
Truth table66%2/3
A and B
A= $listenersB= @$listeners
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $listenersB= @$listeners
ABresult
0X0
100
111
29 0 $_->(@args) for @$listeners;
30 0 return 1;
31 }
32  
33 15 1;
34  
35 __END__
« blib/lib/Text/Nunjucks/Runtime/Frame.pm ↑ Summary blib/lib/Text/Nunjucks/Globals.pm »