blib/lib/App/Netdisco/Worker/Plugin/Discover/Hooks.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 72 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Worker::Plugin::Discover::Hooks;
2  
3 use Dancer ':syntax';
4 use App::Netdisco::Worker::Plugin;
5 use aliased 'App::Netdisco::Worker::Status';
6  
7 use App::Netdisco::Util::Worker;
8 use App::Netdisco::Util::Permission qw/acl_matches acl_matches_only/;
9  
10 register_worker({ phase => 'late' }, sub {
11 my ($job, $workerconf) = @_;
12 my $count = 0;
13  
14 my $best = $job->best_status;
15 if (Status->$best->level != Status->done->level) {
16 return Status
17 ->info(sprintf ' [%s] hooks - skipping due to incomplete job', $job->device);
18 }
19  
20 foreach my $conf (@{ setting('hooks') }) {
21 my $no = ($conf->{'filter'}->{'no'} || []);
22 my $only = ($conf->{'filter'}->{'only'} || []);
23  
24 next if acl_matches( $job->device, $no );
25 next unless acl_matches_only( $job->device, $only);
26  
27 if ($conf->{'event'} eq 'discover') {
28 $count += queue_hook('discover', $conf);
29 debug sprintf ' [%s] hooks - %s queued', 'discover', $job->device;
30 }
31  
32 if (vars->{'device_changed'} and $conf->{'event'} eq 'updated_device') {
33 $count += queue_hook('updated_device', $conf);
34 debug sprintf ' [%s] hooks - %s queued', 'updated_device', $job->device;
35 }
36  
37 if (vars->{'new_device'} and $conf->{'event'} eq 'new_device') {
38 $count += queue_hook('new_device', $conf);
39 debug sprintf ' [%s] hooks - %s queued', 'new_device', $job->device;
40 }
41 }
42  
43 return Status
44 ->info(sprintf ' [%s] hooks - %d queued', $job->device, $count);
45 });
46  
47 true;