blib/lib/Net/DNS/Async/Simple.pm

filter: Statementstmt 93.4% 57 / 61 Branchbran 68.1% 15 / 22 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 81.9% 86 / 105 CC 18 SCAR 21.2
CC
18
Cov
84%
massDNSLookup
12.0
__ANON__
8.8
BEGIN
1.0
CRAP 8.3
↑ Summary
1 package Net::DNS::Async::Simple;
2 1 $Net::DNS::Async::Simple::VERSION = '1.161090';
3 1 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Net::DNS::Async;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Net::DNS::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub massDNSLookup {
Subroutine massDNSLookup: called CC=11 SCAR=24.9
Pod documented
10 1 ▶ my $list = shift
Branch: 1 branch
BranchTrueFalseTotal
my $list = shift() or die "Net::DNS::Async::Simple: one argument required" 1 0 1
11 or die 'Net::DNS::Async::Simple: one argument required';
12 1 ▶ die 'Net::DNS::Async::Simple: first required argument must be an ARRAY reference'
Branch: 1 branch
BranchTrueFalseTotal
if not ref $list or ref $list ne "ARRAY" 0 1 1
Condition33%1/3
not ref $list or ref $list ne "ARRAY"
l!l&&r!l&&!r
001
MC/DC0%0/2
not ref $list or ref $list ne "ARRAY"
not ref $list ref $list ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $listB= ref $list ne "ARRAY"
ABresult
1X1
011
000
13 if not ref $list or ref $list ne 'ARRAY';
14 1 my $asyncs = {};
15  
16 2 ▶ my $callback = sub {
Subroutine __ANON__: called CC=8 SCAR=21.8
17 2 my ($index, $response) = @_;
18 2 my $item = $list->[$index];
19 2 ▶ if(not $response) { #timeout
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 0 2 2
20 0 $item->{timeout} = 1;
21 0 return;
22 }
23 2 my @answers = $response->answer;
24 2 ▶ if(not scalar @answers) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @answers) 0 2 2
25 0 $item->{error} = "returned no answers via";
26 0 return;
27 }
28 2 foreach my $answer (@answers) {
29 2 $item->{NetDNSAnswer} = {};
30 2 foreach my $key (keys %$answer) {
31 12 my $value = $answer->{$key};
32 12 ▶ if(ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 3 9 12
33 3 $item->{NetDNSAnswer}->{$key} = Storable::dclone($value);
34 } else {
35 9 $item->{NetDNSAnswer}->{$key} = $value;
36 }
37 }
38 2 ▶ if(ref $answer eq 'Net::DNS::RR::A') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $answer eq 'Net::DNS::RR::A') { } 1 1 2
elsif (ref $answer eq 'Net::DNS::RR::PTR') { } 1 0 1
39 1 $item->{name} = $answer->name;
40 1 $item->{address} = $answer->address;
41 } elsif(ref $answer eq 'Net::DNS::RR::PTR') {
42 1 $item->{ptrdname} = $answer->ptrdname;
43 }
44 }
45 1 };
46  
47 1 my $i = 0;
48 1 ▶ while($list->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->[$i]) 2 1 3
49 2 my $item = $list->[$i];
50 2 my $j = $i;
51 2 local $Data::Dumper::Sortkeys = 1;
52 2 ▶ my $nameServerInfo = $item->{nameServers} || [];
Condition100%2/2
$item->{'nameServers'} || []
l!l
11
MC/DC100%1/1
$item->{'nameServers'} || []
$item->{'nameServers'}
Truth table100%2/2
A
A= $item->{'nameServers'}
Aresult
11
00
53 2 my $nameServerKey = Data::Dumper::Dumper $nameServerInfo;
54 2 ▶ if(not $asyncs->{$nameServerKey}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($asyncs->{$nameServerKey}) 2 0 2
55 2 $asyncs->{$nameServerKey} = Net::DNS::Async->new(QueueSize => 20, Retries => 3);
56 2 ▶ if($item->{nameServers}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"nameServers"}) 1 1 2
57 $asyncs->{$nameServerKey}->{Resolver} = Net::DNS::Resolver->new(
58 nameservers => $item->{nameServers}
59 1 );
60 }
61 }
62 2 ▶ if($list->[$j]->{query}->[0] and $list->[$j]->{query}->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->[$j]{"query"}[0] and $list->[$j]{"query"}[1]) 2 0 2
Condition33%1/3
$list->[$j]{"query"}[0] and $list->[$j]{"query"}[1]
!ll&&!rl&&r
002
MC/DC0%0/2
$list->[$j]{"query"}[0] and $list->[$j]{"query"}[1]
$list->[$j]{"query"}[0] $list->[$j]{"query"}[1]
Truth table33%1/3
A and B
A= $list->[$j]{"query"}[0]B= $list->[$j]{"query"}[1]
ABresult
0X0
100
111
63 $asyncs->{$nameServerKey}->add(
64 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
65 2 $callback->($j, @_)
66 2 }, @{$list->[$j]->{query}}
67 );
68 }
69 2 $i++;
70 }
71 1 foreach my $nameServerKey (keys %{$asyncs}) {
72 2 $asyncs->{$nameServerKey}->await;
73 }
74 1 return undef;
75 }
76  
77 1 1;
78  
79 __END__
↑ Summary