Events/Listeners.pm

filter: Statementstmt 37.5% 12 / 32 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 3 / 8 Podpod 100% 1 / 1 totaltotal 29.6% 16 / 54 CC 8 SCAR 27.6
CC
8
Cov
28%
_listener
30.0
startup
20.0
__ANON__
2.0
CRAP 15.8
↑ Summary Events/AsyncListener.pm »
1 package Mojolicious::Plugin::Events::Listeners;
2 2 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use Mojo::Loader qw(find_modules load_class);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Mojo::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶has app => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') };
Subroutine __ANON__: not called CC=1 SCAR=1.2
8 0 ▶has namespaces => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
9  
10 =head2 startup
11  
12 Start listeners
13  
14 =cut
15  
16 0 ▶sub startup {
Subroutine startup: not called CC=4 SCAR=30.0
Pod documented
17 0 my ($self, $dispatcher) = @_;
18  
19 0 my @namespaces = @{ $self->namespaces };
20 0 push(@namespaces, 'Mojolicious::Plugin::Events::Listeners');
21  
22 0 for my $namespace (@namespaces) {
23 0 for my $module (find_modules($namespace)) {
24 0 my $loaded = _listener($module, 1);
25  
26 0 ▶ if (!$loaded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loaded) 0 0 0
27 0 warn "Could not load $module";
28
29 0 next;
30 }
31  
32 # Initialize listener
33 0 my $listener = $loaded->new(app => $self->app);
34 0 Scalar::Util::weaken $listener->{ app };
35
36 0 ▶ $dispatcher->on($listener->event => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 my $self = shift;
38
39 0 return $listener->handle(@_);
40 0 });
41 }
42 }
43 }
44  
45 =head2 _listener
46  
47 Load listener
48  
49 =cut
50  
51 0 ▶sub _listener {
Subroutine _listener: not called CC=5 SCAR=34.0
52 0 my ($module, $fatal) = @_;
53  
54 0 ▶ return $module->isa('Mojolicious::Plugin::Events::Listener') ? $module : undef
Branch: 2 branches
BranchTrueFalseTotal
unless my $e = load_class($module) 0 0 0
$module->isa('Mojolicious::Plugin::Events::Listener') ? : 0 0 0
55 unless my $e = load_class $module;
56 0 ▶ $fatal && ref $e ? die $e : return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fatal && ref $e ? : 0 0 0
Condition0%0/3
$fatal and ref $e
!ll&&!rl&&r
000
MC/DC0%0/2
$fatal and ref $e
$fatal ref $e
Truth table0%0/3
A and B
A= $fatalB= ref $e
ABresult
0X0
100
111
57 }
58  
59 2 1;
↑ Summary Events/AsyncListener.pm »