line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
22
|
use 5.10.0; |
|
2
|
|
|
|
|
6
|
|
2
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
38
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
97
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Map::Metro::Emitter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Event emitter for hooks |
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY |
9
|
|
|
|
|
|
|
our $VERSION = '0.2404'; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
6
|
use Map::Metro::Elk; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
12
|
2
|
|
|
2
|
|
2673
|
use List::Util qw/none/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
13
|
2
|
|
|
2
|
|
8
|
use Types::Standard qw/ArrayRef Str HashRef/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
15
|
|
14
|
2
|
|
|
2
|
|
2206
|
use Map::Metro::Hook; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
78
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
11
|
use Module::Pluggable search_path => ['Map::Metro::Plugin::Hook'], require => 1, sub_name => 'found_plugins'; |
|
2
|
|
|
|
|
2
|
|
|
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
|
|
|
|
|
19
|
foreach my $pluginname ($self->found_plugins) { |
52
|
8
|
|
|
|
|
5387
|
(my $actual = $pluginname) =~ s{^Map::Metro::Plugin::Hook::}{}; |
53
|
8
|
50
|
|
0
|
|
299
|
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
|
68
|
my $self = shift; |
74
|
80
|
|
|
|
|
63
|
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
|
|
|
|
|
4
|
$self->emit('before_add_routing', $routing); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
sub before_start_routing { |
85
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
86
|
1
|
|
|
|
|
5
|
$self->emit('before_start_routing'); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub emit { |
90
|
82
|
|
|
82
|
0
|
66
|
my $self = shift; |
91
|
82
|
|
|
|
|
77
|
my $event = shift; |
92
|
82
|
|
|
|
|
100
|
my @args = @_; |
93
|
|
|
|
|
|
|
|
94
|
82
|
|
|
0
|
|
2627
|
my @hooks = $self->filter_registered_hooks(sub { $_->event eq $event }); |
|
0
|
|
|
|
|
0
|
|
95
|
|
|
|
|
|
|
|
96
|
82
|
|
|
|
|
259
|
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.2404, released 2016-04-30. |
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 |