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

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 52 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::Delete::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 'delete') {
28 $count += queue_hook('delete', $conf);
29 debug sprintf ' [%s] hooks - %s queued', 'delete', $job->device;
30 }
31 }
32  
33 return Status
34 ->info(sprintf ' [%s] hooks - %d queued', $job->device, $count);
35 });
36  
37 true;