SenderBase/Query/DNS.pm

filter: Statementstmt 33.3% 17 / 51 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 27.1% 22 / 81 CC 12 SCAR 37.0
CC
12
Cov
24%
results
72.0
new
30.0
BEGIN
1.0
CRAP 40.6
↑ Summary SenderBase/Query/HTTP.pm »
1 # $Id: DNS.pm,v 1.3 2003/07/03 15:11:04 matt Exp $
2  
3 package Net::SenderBase::Query::DNS;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($HOST);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 $HOST = 'test.senderbase.org';
8  
9 1 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Net::SenderBase::Results;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
14 0 my $class = shift;
15 0 my %attrs = @_;
16  
17 0 ▶ $attrs{Address} || die "No address";
Branch: 1 branch
BranchTrueFalseTotal
$attrs{"Address"} or die "No address" 0 0 0
18 0 ▶ $attrs{Host} ||= $HOST;
Condition0%0/3
$attrs{"Host"} ||= $Net::SenderBase::Query::DNS::HOST
l!l&&r!l&&!r
000
MC/DC0%0/2
$attrs{"Host"} ||= $Net::SenderBase::Query::DNS::HOST
$attrs{"Host"} $Net::SenderBase::Query::DNS::HOST
Truth table0%0/3
A ||= B
A= $attrs{"Host"}B= $Net::SenderBase::Query::DNS::HOST
ABresult
1X1
011
000
19 0 ▶ $attrs{Timeout} || die "No timeout";
Branch: 1 branch
BranchTrueFalseTotal
$attrs{"Timeout"} or die "No timeout" 0 0 0
20  
21 0 my $self = bless { %attrs }, $class;
22  
23 0 my $res = Net::DNS::Resolver->new();
24 0 my $sel = IO::Select->new();
25  
26 0 my $reversed_ip = join('.', reverse(split(/\./,$attrs{Address})));
27  
28 0 ▶ my $mask = $attrs{Mask} ? ".$attrs{Mask}" : '';
Branch: 1 branch
BranchTrueFalseTotal
$attrs{'Mask'} ? : 0 0 0
29
30 0 $sel->add($res->bgsend("$reversed_ip$mask.$attrs{Host}", "TXT"));
31  
32 0 $self->{_sel} = $sel;
33  
34 0 return $self;
35 }
36  
37 0 ▶sub results {
Subroutine results: not called CC=8 SCAR=42.8
Pod undocumented
38 0 my $self = shift;
39  
40 0 my $res = Net::DNS::Resolver->new();
41 0 my $sel = $self->{_sel};
42  
43 0 my @ready = $sel->can_read($self->{Timeout});
44  
45 0 ▶ @ready || die "Timeout occurred getting results";
Branch: 1 branch
BranchTrueFalseTotal
@ready or die "Timeout occurred getting results" 0 0 0
46  
47 0 my @lines;
48
49 0 for my $socket (@ready) {
50 0 my $query = $res->bgread($socket);
51 0 $sel->remove($socket);
52 0 undef($socket);
53  
54 0 ▶ if (!$query) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query) 0 0 0
55 0 die $res->errorstring;
56 }
57  
58 0 foreach my $rr ($query->answer) {
59 0 ▶ next unless $rr->type eq 'TXT';
Branch: 1 branch
BranchTrueFalseTotal
unless $rr->type eq "TXT" 0 0 0
60 0 my $line = $rr->txtdata;
61 0 ▶ if ($line =~ s/^(\d+)-//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^(\d+)-//) { } 0 0 0
62 0 my $id = $1;
63 0 $lines[$id] = $line;
64 }
65 else {
66 0 die "Unable to parse TXT record: $line";
67 }
68 }
69 }
70  
71 0 ▶ @lines || die "No results came back for $self->{Address}";
Branch: 1 branch
BranchTrueFalseTotal
@lines or die qq[No results came back for $self->{"Address"}] 0 0 0
72
73 0 return Net::SenderBase::Results->cons($self->{Address}, join('', @lines));
74 }
75  
76 1 1;
↑ Summary SenderBase/Query/HTTP.pm »