File Coverage

blib/lib/IO/Async/Resolver/DNS/NetDNSImpl.pm
Criterion Covered Total %
statement 19 22 86.3
branch 1 4 25.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 2 2 100.0
total 30 37 81.0


line stmt bran cond sub pod time code
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     3   957 use strict;
  3         6  
  3         98  
9 3     3   14 use warnings;
  3         5  
  3         119  
10              
11             our $VERSION = '0.04';
12              
13 3     3   906 use Net::DNS::Resolver;
  3         47513  
  3         591  
14              
15             my $res;
16             sub _resolve
17             {
18 2     2   6 my ( $method, $dname, $class, $type ) = @_;
19              
20 2   66     21 $res ||= Net::DNS::Resolver->new;
21              
22 2         519 my $pkt = $res->$method( $dname, $type, $class ); # !order
23 2 50       17611 if( !$pkt ) {
24 0         0 my $errorstring = $res->errorstring;
25             # Net::DNS::Resolver yields NOERROR for successful DNS queries that just
26             # didn't yield any records of the type we wanted. Rewrite that into
27             # NODATA instead
28 0 0       0 die "NODATA\n" if $errorstring eq "NOERROR";
29 0         0 die "$errorstring\n";
30             }
31              
32             # placate Net::DNS::Packet bug
33 2         9 $pkt->answer; $pkt->authority; $pkt->additional;
  2         17  
  2         15  
34              
35 2         14 return $pkt->data;
36             }
37              
38              
39 1     1 1 8 sub IO::Async::Resolver::DNS::res_query { _resolve( query => @_ ) }
40 1     1 1 4010 sub IO::Async::Resolver::DNS::res_search { _resolve( search => @_ ) }
41              
42             0x55AA;