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

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 47 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;
2  
3 use Dancer ':syntax';
4 use App::Netdisco::Worker::Plugin;
5 use aliased 'App::Netdisco::Worker::Status';
6  
7 use App::Netdisco::Util::Device 'delete_device';
8  
9 register_worker({ phase => 'check' }, sub {
10 return Status->error('Missing device (-d).')
11 unless shift->device;
12 return Status->done('Delete is able to run');
13 });
14  
15 register_worker({ phase => 'main' }, sub {
16 my ($job, $workerconf) = @_;
17 my ($device, $port) = map {$job->$_} qw/device port/;
18  
19 return Status->error('Missing device (-d).')
20 unless defined $device;
21  
22 if (! $device->in_storage) {
23 return Status->error(sprintf "unknown device: %s.", $device);
24 }
25  
26 # support for Hooks
27 vars->{'hook_data'} = { $device->get_columns };
28 delete vars->{'hook_data'}->{'snmp_comm'}; # for privacy
29  
30 $port = ($port ? 1 : 0);
31 my $happy = delete_device($device, $port);
32  
33 if ($happy) {
34 return Status->done("Deleted device: $device")
35 }
36 else {
37 return Status->error("Failed to delete device: $device")
38 }
39 });
40  
41 true;