DNS/NetDNSImpl.pm

filter: Statementstmt 78.2% 36 / 46 Branchbran 8.3% 1 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 68.0% 51 / 75 CC 9 SCAR 28.3
CC
9
Cov
64%
_resolve
33.0
BEGIN
1.0
BEGIN
1.0
CRAP 17.0
↑ Summary DNS.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2011-2013 -- leonerd@leonerd.org.uk
5  
6 package IO::Async::Resolver::DNS::NetDNSImpl;
7  
8 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 our $VERSION = '0.06';
12  
13 3 ▶use Net::DNS::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use IO::Async::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use constant HAVE_IO_ASYNC_RESOLVER_EXTENDED_ERROR => ( $IO::Async::Resolver::VERSION >= '0.68' );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use IO::Async::Resolver::DNS::Constants qw( /^ERR_/ );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Net::DNS::Resolver sometimes just sets its error strings to the stringified version of $!
21 3 ▶use constant EAGAIN_STR => do { $! = Errno::EAGAIN; "$!" };
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 my $res;
24 sub _resolve
25 2 ▶{
Subroutine _resolve: called CC=9 SCAR=35.0
26 2 my ( $method, $dname, $class, $type ) = @_;
27  
28 2 ▶ $res ||= Net::DNS::Resolver->new;
Condition66%2/3
$res ||= "Net::DNS::Resolver"->new
l!l&&r!l&&!r
110
MC/DC0%0/2
$res ||= "Net::DNS::Resolver"->new
$res "Net::DNS::Resolver"->new
Truth table66%2/3
A ||= B
A= $resB= "Net::DNS::Resolver"->new
ABresult
1X1
011
000
29  
30 2 my $pkt = $res->$method( $dname, $type, $class ); # !order
31 2 ▶ if( !$pkt ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkt) 0 2 2
32 0 my $errorstring = $res->errorstring;
33 # Net::DNS::Resolver yields NOERROR for successful DNS queries that just
34 # didn't yield any records of the type we wanted. Rewrite that into
35 # NODATA instead
36 0 ▶ $errorstring = "NODATA" if $errorstring eq "NOERROR";
Branch: 1 branch
BranchTrueFalseTotal
if $errorstring eq "NOERROR" 0 0 0
37  
38 0 if( HAVE_IO_ASYNC_RESOLVER_EXTENDED_ERROR ) {
39 # Attempt to convert Net::DNS::Resolver's error strings to our own
40 # constants
41 0 my $err = ERR_UNRECOVERABLE;
42 0 for( $errorstring ) {
43 # RCODE errors in the DNS packet response
44 0 ▶ m/^NODATA$/ and $err = ERR_NO_ADDRESS, last;
Branch: 1 branch
BranchTrueFalseTotal
/^NODATA$/ and $err = 2, last 0 0 0
45 0 ▶ m/^NXDOMAIN$/ and $err = ERR_NO_HOST, last;
Branch: 1 branch
BranchTrueFalseTotal
/^NXDOMAIN$/ and $err = 1, last 0 0 0
46 0 ▶ m/^SRVFAIL$/ and $err = ERR_TEMPORARY, last;
Branch: 1 branch
BranchTrueFalseTotal
/^SRVFAIL$/ and $err = 3, last 0 0 0
47 # libc errno values which arrive as strings :(
48 0 ▶ $_ eq EAGAIN_STR and $err = ERR_TEMPORARY, last;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "Resource temporarily unavailable" and $err = 3, last 0 0 0
49 # It is quite likely this mapping is incomplete. :(
50 }
51  
52 0 die [ "$errorstring", $err ];
53 }
54 else {
55 die "$errorstring\n";
56 }
57 }
58  
59 # placate Net::DNS::Packet bug
60 2 $pkt->answer; $pkt->authority; $pkt->additional;
61  
62 2 return $pkt->data;
63 }
64  
65 1 ▶sub IO::Async::Resolver::DNS::res_query { _resolve( query => @_ ) }
Subroutine res_query: called CC=1 SCAR=0.0
Pod documented
66 1 ▶sub IO::Async::Resolver::DNS::res_search { _resolve( search => @_ ) }
Subroutine res_search: called CC=1 SCAR=0.0
Pod documented
67  
68 3 0x55AA;
↑ Summary DNS.pm »