line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Events::Listeners; |
2
|
1
|
|
|
1
|
|
8
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
171
|
use Mojo::Loader qw(find_modules load_class); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
22
|
use Mojo::Server; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has app => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') }, weak => 1; |
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, 'Mojo::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
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$dispatcher->on($listener->event => sub { |
36
|
0
|
|
|
0
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return $listener->handle(@_); |
39
|
0
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 _listener |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Load listener |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _listener { |
51
|
0
|
|
|
0
|
|
|
my ($module, $fatal) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
return $module->isa('Mojo::Events::Listener') ? $module : undef |
|
|
0
|
|
|
|
|
|
54
|
|
|
|
|
|
|
unless my $e = load_class $module; |
55
|
0
|
0
|
0
|
|
|
|
$fatal && ref $e ? die $e : return undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |