line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Events::Listeners; |
2
|
1
|
|
|
1
|
|
7
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
581
|
use Mojo::Loader qw(find_modules load_class); |
|
1
|
|
|
|
|
36151
|
|
|
1
|
|
|
|
|
72
|
|
5
|
1
|
|
|
1
|
|
488
|
use Mojo::Server; |
|
1
|
|
|
|
|
8118
|
|
|
1
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has app => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') }, weak => 1; |
8
|
|
|
|
|
|
|
has registered => sub { [] }; |
9
|
|
|
|
|
|
|
has namespaces => sub { [] }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head2 new |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Initialize listeners |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(@_); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my @namespaces = @{ $self->namespaces }; |
|
0
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
push(@namespaces, 'Mojo::Events::Listeners'); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
for my $namespace (@namespaces) { |
24
|
0
|
|
|
|
|
|
for my $module (find_modules($namespace)) { |
25
|
0
|
|
|
|
|
|
my $loaded = _listener($module, 1); |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if (!$loaded) { |
28
|
0
|
|
|
|
|
|
warn "Could not load $module"; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
next; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Initialize listener |
34
|
0
|
|
|
|
|
|
my $listener = $loaded->new(app => $self->app); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
push(@{ $self->registered }, $listener); |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 register |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Append new listener |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub register { |
50
|
0
|
|
|
0
|
1
|
|
my ($self, $listener) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (!$listener->isa('Mojo::Events::Listener')) { |
53
|
0
|
|
|
|
|
|
warn "Invalid listener"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
push(@{ $self->registered }, $listener); |
|
0
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 _listener |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Load listener |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _listener { |
66
|
0
|
|
|
0
|
|
|
my ($module, $fatal) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
return $module->isa('Mojo::Events::Listener') ? $module : undef |
|
|
0
|
|
|
|
|
|
69
|
|
|
|
|
|
|
unless my $e = load_class $module; |
70
|
0
|
0
|
0
|
|
|
|
$fatal && ref $e ? die $e : return undef; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |