| 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'
ref $type or $type
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | croak "Argument to new() must be a reference to a hash\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $ref and defined $ref->{"BaseDomain"}
defined $ref and defined $ref->{"Hash"}
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"}
Truth table33%1/3
A and B
A= defined $refB= defined $ref->{"Hash"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | return 1 if $pos == 0 and (length($q) <= length($d)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pos == 0 and length $q <= length $d
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | ▶ | return 1 if substr($q, $pos - 1, 1) eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
exists $self->{"hash"}{$ip} or exists $self->{"hash"}{$name} or exists $self->{"hash"}{$name . '.'}
exists $self->{"hash"}{$ip} or exists $self->{"hash"}{$name}
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 . '.'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 . '.'}
$self->{"hash"}{$ip} or $self->{"hash"}{$name}
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 . '.'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | ▶ | if (!ref $set) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
$q->qtype eq "ANY" || $rr->type eq $q->qtype and $rr->class eq $q->qclass
$q->qtype eq "ANY" or $rr->type eq $q->qtype
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return NS_FAIL unless $sub eq uc $sub; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||