Metro/Emitter.pm

filter: Statementstmt 79.6% 47 / 59 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.2% 13 / 16 Podpod 0.0% 0 / 6 totaltotal 73.4% 61 / 83 CC 5 SCAR 7.4
CC
5
Cov
79%
register
6.0
BUILD
4.1
emit
2.1
CRAP 2.1
« Metro/Cmd/AllRoutes.pm ↑ Summary Metro/Graph/Routing.pm »
1 14 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Map::Metro::Emitter;
6  
7 # ABSTRACT: Event emitter for hooks
8 14 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 14 our $VERSION = '0.2405';
10  
11 14 ▶use Map::Metro::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use List::Util qw/none/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use Types::Standard qw/ArrayRef Str HashRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 14 ▶use Map::Metro::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 14 ▶use Module::Pluggable search_path => ['Map::Metro::Plugin::Hook'], require => 1, sub_name => 'found_plugins';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 14 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 14 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 14 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 4 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=14.2
Pod undocumented
48 4 my $self = shift;
49  
50 PLUGIN:
51 4 foreach my $pluginname ($self->found_plugins) {
52 8 (my $actual = $pluginname) =~ s{^Map::Metro::Plugin::Hook::}{};
53 0 ▶ next PLUGIN if none { $_ eq $actual } $self->all_wanted_hook_plugins;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $_ eq $actual; } , $self->all_wanted_hook_plugins) 8 0 8
54  
55 0 my $plugin = $pluginname->new;
56 0 $self->register($plugin);
57 0 $self->add_plugin($actual => $plugin);
58 }
59 }
60 0 ▶sub register {
Subroutine register: not called CC=2 SCAR=17.9
Pod undocumented
61 0 my $self = shift;
62 0 my $plugin = shift;
63  
64 0 my %hooks_list = $plugin->register;
65  
66 0 foreach my $event (keys %hooks_list) {
67 0 my $hook = Map::Metro::Hook->new(event => $event, action => $hooks_list{ $event }, plugin => $plugin);
68 0 $self->add_registered_hook($hook);
69 }
70 }
71  
72 80 ▶sub before_add_station {
Subroutine before_add_station: called CC=1 SCAR=0.0
Pod undocumented
73 80 my $self = shift;
74 80 my $station = shift;
75  
76 80 $self->emit('before_add_station', $station);
77 }
78 1 ▶sub before_add_routing {
Subroutine before_add_routing: called CC=1 SCAR=0.0
Pod undocumented
79 1 my $self = shift;
80 1 my $routing = shift;
81  
82 1 $self->emit('before_add_routing', $routing);
83 }
84 1 ▶sub before_start_routing {
Subroutine before_start_routing: called CC=1 SCAR=0.0
Pod undocumented
85 1 my $self = shift;
86 1 $self->emit('before_start_routing');
87 }
88  
89 82 ▶sub emit {
Subroutine emit: called CC=2 SCAR=7.4
Pod undocumented
90 82 my $self = shift;
91 82 my $event = shift;
92 82 my @args = @_;
93  
94 0 ▶ my @hooks = $self->filter_registered_hooks(sub { $_->event eq $event });
Subroutine __ANON__: not called CC=1 SCAR=1.2
95  
96 82 foreach my $hook (@hooks) {
97 0 $hook->action->($hook->plugin, @args);
98 }
99 }
100  
101 14 __PACKAGE__->meta->make_immutable;
102  
103 14 1;
104  
105 __END__
« Metro/Cmd/AllRoutes.pm ↑ Summary Metro/Graph/Routing.pm »