Method/Hash.pm

filter: Statementstmt 92.4% 61 / 66 Branchbran 61.5% 16 / 26 Conditioncond 59.3% 19 / 32 MC/DCmcdc 17.6% 3 / 17 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 2 totaltotal 70.7% 109 / 154 CC 26 SCAR 22.3
CC
26
Cov
77%
ANY
13.7
new
13.3
AUTOLOAD
5.3
CRAP 9.3
« Method.pm ↑ Summary Method/Status.pm »
1 package Net::DNS::Method::Hash;
2  
3 2 require 5.005_62;
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Net::DNS::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use vars qw($VERSION @ISA $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 @ISA = qw(Net::DNS::Method);
13  
14 2 $VERSION = '2.00';
15  
16 # Default responses
17 2 our $DEF_ZONE = 'some.com';
18  
19 2 ▶sub new {
Subroutine new: called CC=8 SCAR=25.8
Pod undocumented
20 2 my $type = shift;
21 2 ▶ my $class = ref($type) || $type || "Net::DNS::Method::Hash";
Condition40%2/5
ref $type || $type || 'Net::DNS::Method::Hash'
l!l
20
ref $type or $type
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $type || $type || 'Net::DNS::Method::Hash'
ref $type $type
Truth table33%1/3
A or B
A= ref $typeB= $type
ABresult
1X1
011
000
22  
23 2 my $ref = shift;
24  
25 2 ▶ croak "Argument to new() must be a reference to a hash\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "HASH" 0 2 2
26 if (ref $ref ne 'HASH');
27  
28 my $self =
29 {
30 zone => (defined($ref) && defined($ref->{BaseDomain}) ?
31 lc $ref->{BaseDomain} : $DEF_ZONE),
32 hash => (defined($ref) && defined($ref->{Hash}) ?
33 2 ▶ $ref->{Hash} : {}),
Branch: 2 branches
BranchTrueFalseTotal
defined $ref && defined $ref->{'BaseDomain'} ? : 2 0 2
defined $ref && defined $ref->{'Hash'} ? : 2 0 2
Condition33%2/6
defined $ref and defined $ref->{"BaseDomain"}
!ll&&!rl&&r
002
defined $ref and defined $ref->{"Hash"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $ref and defined $ref->{"BaseDomain"}
defined $ref defined $ref->{"BaseDomain"}
MC/DC0%0/2
defined $ref and defined $ref->{"Hash"}
defined $ref defined $ref->{"Hash"}
Truth table33%1/3
A and B
A= defined $refB= defined $ref->{"BaseDomain"}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $refB= defined $ref->{"Hash"}
ABresult
0X0
100
111
34 };
35
36 2 return bless $self, $class;
37 }
38  
39 8 ▶sub _match {
Subroutine _match: called CC=5 SCAR=16.4
40 8 my $q = lc shift;
41 8 my $d = shift;
42  
43 8 $q =~ s/\.+$//;
44  
45 8 my $pos = index($q, $d);
46  
47 8 ▶ return 1 if $q eq $d;
Branch: 1 branch
BranchTrueFalseTotal
if $q eq $d 2 6 8
48 6 ▶ return 1 if $pos == 0 and (length($q) <= length($d));
Branch: 1 branch
BranchTrueFalseTotal
if $pos == 0 and length $q <= length $d 0 6 6
Condition33%1/3
$pos == 0 and length $q <= length $d
!ll&&!rl&&r
600
MC/DC0%0/2
$pos == 0 and length $q <= length $d
$pos == 0 length $q <= length $d
Truth table33%1/3
A and B
A= $pos == 0B= length $q <= length $d
ABresult
0X0
100
111
49 6 ▶ return 1 if substr($q, $pos - 1, 1) eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if substr($q, $pos - 1, 1) eq "." 4 2 6
50 2 return 0;
51 }
52  
53 8 ▶sub ANY {
Subroutine ANY: called CC=13 SCAR=26.2
Pod undocumented
54 8 my $self = shift;
55 8 my $q = shift;
56 8 my $ans = shift;
57  
58 8 ▶ if (_match($q->qname, $self->{zone})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($q->qname, $self->{"zone"})) 6 2 8
59  
60 # warn "match ", $q->qname, "\n";
61  
62 6 my $ip = lc substr($q->qname, 0, index($q->qname, $self->{zone}) - 1);
63  
64 # warn "lookup of <$ip>\n";
65  
66 6 my $name = $q->qname;
67 6 $name =~ s/\.+$//;
68  
69 6 ▶ if (exists $self->{hash}->{$ip}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"hash"}{$ip} or exists $self->{"hash"}{$name} or exists $self->{"hash"}{$name . '.'}) 4 2 6
Condition100%6/6
exists $self->{"hash"}{$ip} or exists $self->{"hash"}{$name} or exists $self->{"hash"}{$name . '.'}
l!l&&r!l&&!r
312
exists $self->{"hash"}{$ip} or exists $self->{"hash"}{$name}
l!l&&r!l&&!r
123
MC/DC100%3/3
exists $self->{"hash"}{$ip} or exists $self->{"hash"}{$name} or exists $self->{"hash"}{$name . '.'}
exists $self->{"hash"}{$ip} exists $self->{"hash"}{$name} exists $self->{"hash"}{$name . '.'}
Truth table100%4/4
A or B or C
A= exists $self->{"hash"}{$ip}B= exists $self->{"hash"}{$name}C= exists $self->{"hash"}{$name . '.'}
ABCresult
1XX1
01X1
0011
0000
70 or exists $self->{hash}->{$name}
71 or exists $self->{hash}->{$name . "."})
72 {
73  
74 # warn "found ", $q->qname, "\n";
75  
76 # In this case, we should try to answer
77 # this question...
78  
79 4 my $answers = 0;
80  
81 # warn "question ", $q->qname, " resolves to $ip\n";
82 # warn "class ", $q->qclass, "\n";
83 # warn "type ", $q->qtype, "\n";
84  
85 my $set = $self->{hash}->{$ip}
86 || $self->{hash}->{$name}
87 4 ▶ || $self->{hash}->{$name . "."};
Condition83%5/6
$self->{'hash'}{$ip} || $self->{'hash'}{$name} || $self->{'hash'}{$name . '.'}
l!l&&r!l&&!r
310
$self->{"hash"}{$ip} or $self->{"hash"}{$name}
l!l&&r!l&&!r
121
MC/DC0%0/3
$self->{'hash'}{$ip} || $self->{'hash'}{$name} || $self->{'hash'}{$name . '.'}
$self->{"hash"}{$ip} $self->{"hash"}{$name} $self->{'hash'}{$name . '.'}
Truth table75%3/4
A or B || C
A= $self->{"hash"}{$ip}B= $self->{"hash"}{$name}C= $self->{'hash'}{$name . '.'}
ABCresult
1XX1
01X1
0011
0000
88  
89 4 ▶ if (!ref $set) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $set) 0 4 4
90 0 $set = [ $set ];
91 }
92
93 4 for my $data (@{$set}) {
94 4 my $rr = new Net::DNS::RR $q->qname . " " . $data;
95
96 # warn "Check against rr type=", $rr->type, " class=",
97 # $rr->class, "\n";
98
99 4 ▶ if (($q->qtype eq 'ANY' or $rr->type eq $q->qtype)
Branch: 1 branch
BranchTrueFalseTotal
if ($q->qtype eq "ANY" || $rr->type eq $q->qtype and $rr->class eq $q->qclass) 4 0 4
Condition50%3/6
$q->qtype eq "ANY" || $rr->type eq $q->qtype and $rr->class eq $q->qclass
!ll&&!rl&&r
004
$q->qtype eq "ANY" or $rr->type eq $q->qtype
l!l&&r!l&&!r
130
MC/DC0%0/3
$q->qtype eq "ANY" || $rr->type eq $q->qtype and $rr->class eq $q->qclass
$q->qtype eq "ANY" $rr->type eq $q->qtype $rr->class eq $q->qclass
Truth table40%2/5
A or B and C
A= $q->qtype eq "ANY"B= $rr->type eq $q->qtypeC= $rr->class eq $q->qclass
ABCresult
00X0
1X00
0100
1X11
0111
100 and $rr->class eq $q->qclass)
101 {
102 4 $ans->push('answer', $rr);
103 4 ++ $answers;
104 }
105 }
106
107 4 ▶ if ($answers) { # If we have something to say, we
Branch: 1 branch
BranchTrueFalseTotal
if ($answers) 4 0 4
108 # return success...
109  
110 4 $ans->header->rcode('NOERROR');
111 4 return NS_OK | NS_STOP;
112 }
113 }
114 }
115  
116 # warn "NS_FAIL\n";
117 4 return NS_FAIL;
118 }
119  
120 2 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=16.7
121 2 my $sub = $AUTOLOAD;
122 2 $sub =~ s/.*:://;
123  
124 # Insure that the called method has an all
125 # uppercase name. This avoids any clash with
126 # future extensions for these handlers, which
127 # will use mixed case or lowercase.
128  
129 2 ▶ return undef if $sub eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $sub eq "DESTROY" 2 0 2
130 0 ▶ return NS_FAIL unless $sub eq uc $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub eq uc $sub 0 0 0
131  
132 0 ▶ *$sub = sub { ANY @_; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
133 0 goto &$sub;
134 }
135  
136 2 1;
137 __END__
« Method.pm ↑ Summary Method/Status.pm »