File Coverage

blib/lib/DNS/BL/cmds.pm
Criterion Covered Total %
statement 26 29 89.6
branch 2 4 50.0
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 36 42 85.7


line stmt bran cond sub pod time code
1             package DNS::BL::cmds;
2              
3 2     2   1757 use DNS::BL;
  2         5  
  2         63  
4              
5 2     2   57 use 5.006001;
  2         7  
  2         118  
6 2     2   12 use strict;
  2         4  
  2         86  
7 2     2   11 use warnings;
  2         4  
  2         93  
8              
9 2     2   12 use Carp;
  2         3  
  2         791  
10              
11             our $VERSION = '0.00_01';
12             $VERSION = eval $VERSION; # see L
13              
14             # Preloaded methods go here.
15              
16             =pod
17              
18             =head1 NAME
19              
20             DNS::BL::cmds - Base class for DNS::BL commands
21              
22             =head1 SYNOPSIS
23              
24             use DNS::BL::cmds;
25              
26             =head1 DESCRIPTION
27              
28             This module provides template functions that must be overriden by the
29             actual C commands, as well as its documentation. This behaves
30             as a pure-virtual class.
31              
32             The following methods are implemented by this module:
33              
34             =over
35              
36             =item C<-Eexecute($dns_bl, $verb, @arguments)>
37              
38             This method is invoked by C whenever parsing of a command
39             line with a given verb is requested. The first argument, is a
40             reference to the invoking C object. The second argument is
41             the verb that caused this invocation. Any additional parameters, are
42             passed along as a list or arguments.
43              
44             In scalar context, this method must return one of the C
45             constants defined in L. In list context, the first element of
46             the return value must be this constant. The second argument, must be
47             an explanation message suitable for presenting to an end user.
48              
49             =cut
50              
51 0     0 1 0 sub execute { croak "Must override ->execute()"; }
52              
53             =pod
54              
55             =item C<-Earg_check($caller, $dns_bl, $handler, $verb, \@known, \%arguments)>
56              
57             This method is provided as a courtesy to subclasses. It tests
58             automatically wether passed arguments are understood by the
59             implementation. See the various subclasses for examples of its use.
60              
61             =cut
62              
63             sub arg_check
64             {
65 36     36 1 80 my $caller = shift;
66 36         53 my $bl = shift;
67 36         48 my $command = shift;
68 36         51 my $handler = shift;
69 36         41 my $r_known = shift;
70 36         47 my $r_args = shift;
71              
72 36 50       87 unless ($command eq $handler)
73             {
74             return
75 0         0 (&DNS::BL::DNSBL_ESYNTAX(),
76             "'$caller' invoked by command '$command'");
77             }
78              
79 36         105 for my $k (keys %$r_args)
80             {
81 74 50       108 unless (grep { $k eq $_ } @$r_known)
  356         699  
82             {
83 0         0 return (&DNS::BL::DNSBL_ESYNTAX(),
84             "Unknown argument '$k' to command '$command'");
85             }
86             }
87              
88 36         188 return (&DNS::BL::DNSBL_OK(), "OK");
89             }
90              
91             1;
92             __END__