| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | unless my $e = load_class $module; | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $fatal && ref $e ? die $e : return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fatal and ref $e
MC/DC0%0/2
$fatal and ref $e
$fatal
ref $e
Truth table0%0/3
A and B
A= $fatalB= ref $e
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | 1; | |||||||||||||||||||||||||||