| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Events::Listeners; |
|
2
|
1
|
|
|
1
|
|
15
|
use Mojo::Base -base; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
172
|
use Mojo::Loader qw(find_modules load_class); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
40
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Mojo::Server; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has app => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') }; |
|
8
|
|
|
|
|
|
|
has namespaces => sub { [] }; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head2 startup |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Start listeners |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub startup { |
|
17
|
0
|
|
|
0
|
1
|
|
my ($self, $dispatcher) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my @namespaces = @{ $self->namespaces }; |
|
|
0
|
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if (!$loaded) { |
|
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
|
|
|
|
|
|
|
$dispatcher->on($listener->event => sub { |
|
37
|
0
|
|
|
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
|
|
|
|
|
|
|
sub _listener { |
|
52
|
0
|
|
|
0
|
|
|
my ($module, $fatal) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
return $module->isa('Mojolicious::Plugin::Events::Listener') ? $module : undef |
|
|
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
unless my $e = load_class $module; |
|
56
|
0
|
0
|
0
|
|
|
|
$fatal && ref $e ? die $e : return undef; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |