line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
20
|
use 5.10.0; |
|
2
|
|
|
|
|
4
|
|
2
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
34
|
|
3
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
93
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Map::Metro::Emitter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Event emitter for hooks |
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY |
9
|
|
|
|
|
|
|
our $VERSION = '0.2405'; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
8
|
use Map::Metro::Elk; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
11
|
|
12
|
2
|
|
|
2
|
|
2598
|
use List::Util qw/none/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
130
|
|
13
|
2
|
|
|
2
|
|
7
|
use Types::Standard qw/ArrayRef Str HashRef/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
16
|
|
14
|
2
|
|
|
2
|
|
2084
|
use Map::Metro::Hook; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
10
|
use Module::Pluggable search_path => ['Map::Metro::Plugin::Hook'], require => 1, sub_name => 'found_plugins'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has wanted_hook_plugins => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => ArrayRef[ Str ], |
21
|
|
|
|
|
|
|
traits => ['Array'], |
22
|
|
|
|
|
|
|
handles => { |
23
|
|
|
|
|
|
|
all_wanted_hook_plugins => 'elements', |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
has registered_hooks => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => ArrayRef, |
29
|
|
|
|
|
|
|
traits => ['Array'], |
30
|
|
|
|
|
|
|
handles => { |
31
|
|
|
|
|
|
|
add_registered_hook => 'push', |
32
|
|
|
|
|
|
|
all_registered_hooks => 'elements', |
33
|
|
|
|
|
|
|
filter_registered_hooks => 'grep', |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
has plugins => ( |
37
|
|
|
|
|
|
|
is => 'rw', |
38
|
|
|
|
|
|
|
isa => HashRef, |
39
|
|
|
|
|
|
|
traits => ['Hash'], |
40
|
|
|
|
|
|
|
handles => { |
41
|
|
|
|
|
|
|
add_plugin => 'set', |
42
|
|
|
|
|
|
|
get_plugin => 'get', |
43
|
|
|
|
|
|
|
plugin_names => 'keys', |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub BUILD { |
48
|
4
|
|
|
4
|
0
|
6
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
PLUGIN: |
51
|
4
|
|
|
|
|
20
|
foreach my $pluginname ($self->found_plugins) { |
52
|
8
|
|
|
|
|
5514
|
(my $actual = $pluginname) =~ s{^Map::Metro::Plugin::Hook::}{}; |
53
|
8
|
50
|
|
0
|
|
296
|
next PLUGIN if none { $_ eq $actual } $self->all_wanted_hook_plugins; |
|
0
|
|
|
|
|
0
|
|
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
my $plugin = $pluginname->new; |
56
|
0
|
|
|
|
|
0
|
$self->register($plugin); |
57
|
0
|
|
|
|
|
0
|
$self->add_plugin($actual => $plugin); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub register { |
61
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
62
|
0
|
|
|
|
|
0
|
my $plugin = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my %hooks_list = $plugin->register; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
foreach my $event (keys %hooks_list) { |
67
|
0
|
|
|
|
|
0
|
my $hook = Map::Metro::Hook->new(event => $event, action => $hooks_list{ $event }, plugin => $plugin); |
68
|
0
|
|
|
|
|
0
|
$self->add_registered_hook($hook); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub before_add_station { |
73
|
80
|
|
|
80
|
0
|
70
|
my $self = shift; |
74
|
80
|
|
|
|
|
56
|
my $station = shift; |
75
|
|
|
|
|
|
|
|
76
|
80
|
|
|
|
|
127
|
$self->emit('before_add_station', $station); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
sub before_add_routing { |
79
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
80
|
1
|
|
|
|
|
1
|
my $routing = shift; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
3
|
$self->emit('before_add_routing', $routing); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
sub before_start_routing { |
85
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
86
|
1
|
|
|
|
|
4
|
$self->emit('before_start_routing'); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub emit { |
90
|
82
|
|
|
82
|
0
|
61
|
my $self = shift; |
91
|
82
|
|
|
|
|
65
|
my $event = shift; |
92
|
82
|
|
|
|
|
101
|
my @args = @_; |
93
|
|
|
|
|
|
|
|
94
|
82
|
|
|
0
|
|
2621
|
my @hooks = $self->filter_registered_hooks(sub { $_->event eq $event }); |
|
0
|
|
|
|
|
0
|
|
95
|
|
|
|
|
|
|
|
96
|
82
|
|
|
|
|
279
|
foreach my $hook (@hooks) { |
97
|
0
|
|
|
|
|
|
$hook->action->($hook->plugin, @args); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=pod |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=encoding UTF-8 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Map::Metro::Emitter - Event emitter for hooks |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 VERSION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Version 0.2405, released 2016-07-23. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SOURCE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L<https://github.com/Csson/p5-Map-Metro> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 HOMEPAGE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<https://metacpan.org/release/Map-Metro> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Erik Carlsson <info@code301.com> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Erik Carlsson. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
136
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |