File Coverage

blib/lib/DNS/BL/cmds/delete.pm
Criterion Covered Total %
statement 27 40 67.5
branch 0 14 0.0
condition 0 3 0.0
subroutine 9 10 90.0
pod 1 1 100.0
total 37 68 54.4


line stmt bran cond sub pod time code
1             package DNS::BL::cmds::delete;
2              
3 1     1   1579 use DNS::BL;
  1         2  
  1         28  
4              
5 1     1   30 use 5.006001;
  1         4  
  1         39  
6 1     1   6 use strict;
  1         3  
  1         36  
7 1     1   7 use warnings;
  1         2  
  1         38  
8              
9 1     1   5 use NetAddr::IP;
  1         2  
  1         8  
10 1     1   153 use DNS::BL::cmds;
  1         3  
  1         21  
11 1     1   54 use DNS::BL::Entry;
  1         4  
  1         47  
12              
13 1     1   6 use vars qw/@ISA/;
  1         2  
  1         79  
14              
15             @ISA = qw/DNS::BL::cmds/;
16              
17 1     1   6 use Carp;
  1         2  
  1         427  
18              
19             our $VERSION = '0.00_01';
20             $VERSION = eval $VERSION; # see L
21              
22             # Preloaded methods go here.
23              
24             =pod
25              
26             =head1 NAME
27              
28             DNS::BL::cmds::delete - Delete entries matching IP ranges
29              
30             =head1 SYNOPSIS
31              
32             use DNS::BL::cmds::delete;
33              
34             =head1 DESCRIPTION
35              
36             This module implements the B command, used to remove entries
37             from a DNSBL managed by L. The general syntax of this
38             command, is as follows
39              
40             delete within
41              
42             where each argument has the following function:
43              
44             =over 4
45              
46             =item Bip-addressE>
47              
48             Controls which entries are to be affected. Only entries that are fully
49             enclosed within the given IP address network range will be processed.
50              
51             =back
52              
53             This functionality is provided by the following method:
54              
55             =over
56              
57             =item C<-Eexecute()>
58              
59             See L for information on this method's general purpose
60             and calling convention.
61              
62             This method implements the behavior specified above.
63              
64             =cut
65              
66             sub execute
67             {
68 0     0 1   my $bl = shift;
69 0           my $command = shift;
70 0           my %args = @_;
71              
72 0           my @r = __PACKAGE__->arg_check($bl, 'delete', $command,
73             [ qw/within/ ], \%args);
74 0 0         return wantarray ? (@r) : $r[0]
    0          
75             if $r[0] != &DNS::BL::DNSBL_OK;
76              
77 0           my $e = new DNS::BL::Entry;
78 0           my $ip;
79              
80 0 0 0       unless (exists $args{within} and $ip = new NetAddr::IP $args{within})
81             {
82             return wantarray ?
83 0 0         (&DNS::BL::DNSBL_ESYNTAX(),
84             "'$command' requires a valid 'within' IP address")
85             : &DNS::BL::DNSBL_ESYNTAX();
86             }
87              
88 0           $e->addr($ip);
89              
90             # Fetch results from the database
91 0           @r = $bl->erase($e);
92              
93 0 0         return wantarray ? ($r[0], "'" . __PACKAGE__
    0          
94             . "' failed on delete: $r[1]") : $r[0]
95             if $r[0] != &DNS::BL::DNSBL_OK;
96              
97 0 0         return wantarray ? @r : $r[0];
98             };
99              
100             1;
101             __END__