blib/lib/HTTP/Tiny/Paranoid.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 1 SCAR 6.9
CC
1
Cov
0%
blocked_hosts
2.0
whitelisted_hosts
2.0
BEGIN
2.0
CRAP 2.0
1 package HTTP::Tiny::Paranoid;
2 $HTTP::Tiny::Paranoid::VERSION = '0.06';
3 use strict;
4 use warnings;
5  
6 # ABSTRACT: A safer HTTP::Tiny
7  
8 use HTTP::Tiny 0.070;
9 use parent 'HTTP::Tiny';
10 use Net::DNS::Paranoid;
11 use Class::Method::Modifiers;
12  
13 my $dns = Net::DNS::Paranoid->new;
14  
15 sub blocked_hosts { shift; $dns->blocked_hosts(@_) }
16 sub whitelisted_hosts { shift; $dns->whitelisted_hosts(@_) }
17  
18 around _open_handle => sub {
19 my $next = shift;
20 my $self = shift;
21  
22 my ($req, $scheme, $host, $port, $peer) = @_;
23  
24 if ($peer) {
25 my ($ips, $error) = $dns->resolve($peer);
26 die "$peer: $error\n" if defined $error;
27 die "$peer: did not match resolved IP\n" unless @$ips && $ips->[0] eq $peer;
28 $self->$next($req, $scheme, $host, $port, $peer);
29 }
30 else {
31 my ($ips, $error) = $dns->resolve($host);
32 die "$host: $error\n" if defined $error;
33 die "$host: no IP address found\n" unless @$ips;
34 $self->$next($req, $scheme, $host, $port, $ips->[0]);
35 }
36 };
37  
38 1;
39 __END__