From 924dbfe5de0c92e1dbba6b3ad431182742f9dd0f Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Thu, 6 Nov 2014 11:12:01 -0800 Subject: [PATCH] async_resolver: suppress test warning when Net::DNS::Async not installed. --- lib/Qpsmtpd/Base.pm | 10 +++++----- t/qpsmtpd-base.t | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Qpsmtpd/Base.pm b/lib/Qpsmtpd/Base.pm index b833665..f1612b9 100644 --- a/lib/Qpsmtpd/Base.pm +++ b/lib/Qpsmtpd/Base.pm @@ -63,17 +63,17 @@ sub get_async_resolver { my ( $self, %args ) = @_; return $self->{_async_resolver} if $self->{_async_resolver}; - my $res = Net::DNS::Resolver->new(dnsrch => 0); - $res->tcp_timeout(0); # Net::DNS::Async handles its own timeouts - $res->tcp_timeout(0); - my $async_res; eval 'use Net::DNS::Async'; if ($@) { - warn "Net::DNS::Async failed to load"; + warn "could not load Net::DNS::Async, is it installed?"; return; } + my $res = Net::DNS::Resolver->new(dnsrch => 0); + $res->tcp_timeout(0); # Net::DNS::Async handles its own timeouts + $res->tcp_timeout(0); + $self->{_async_resolver} = Net::DNS::Async->new( %args ); $self->{_async_resolver}{Resolver} = $res; return $self->{_async_resolver}; diff --git a/t/qpsmtpd-base.t b/t/qpsmtpd-base.t index 67d69ea..b0ed7ef 100644 --- a/t/qpsmtpd-base.t +++ b/t/qpsmtpd-base.t @@ -64,6 +64,8 @@ sub __get_resolver { } sub __get_async_resolver { + eval 'use Net::DNS::Async'; + return if ($@); my $res = $base->get_async_resolver() or return; isa_ok( $res, 'Net::DNS::Async', "resolver object, $res"); isa_ok( $res->{Resolver}, 'Net::DNS::Resolver', "resolver object, $res");