line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::DNS; |
2
|
2
|
|
|
2
|
|
28031
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
3
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
6
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
117
|
|
5
|
2
|
|
|
2
|
|
997
|
use URI; |
|
2
|
|
|
|
|
10127
|
|
|
2
|
|
|
|
|
764
|
|
6
|
2
|
|
|
2
|
|
831
|
use Furl; |
|
2
|
|
|
|
|
39573
|
|
|
2
|
|
|
|
|
60
|
|
7
|
2
|
|
|
2
|
|
1214
|
use JSON qw/decode_json/; |
|
2
|
|
|
|
|
16884
|
|
|
2
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
9
|
2
|
|
|
|
|
14
|
rw => [qw/ |
10
|
|
|
|
|
|
|
cd |
11
|
|
|
|
|
|
|
type |
12
|
|
|
|
|
|
|
endpoint |
13
|
|
|
|
|
|
|
ua |
14
|
|
|
|
|
|
|
/], |
15
|
2
|
|
|
2
|
|
248
|
); |
|
2
|
|
|
|
|
2
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
21
|
0
|
|
|
|
|
|
my %args = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
bless { |
24
|
|
|
|
|
|
|
cd => ($args{cd} || $args{dnssec}) ? 1 : 0, |
25
|
|
|
|
|
|
|
type => $args{type} || '', |
26
|
|
|
|
|
|
|
endpoint => $args{endpoint} || 'https://dns.google.com/resolve', |
27
|
0
|
0
|
0
|
|
|
|
ua => $args{ua} || Furl->new, |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub resolve { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $domain, $raw) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
croak "require domain" unless $domain; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $uri = URI->new($self->endpoint); |
37
|
0
|
|
|
|
|
|
$uri->query_form(name => $domain); |
38
|
0
|
0
|
|
|
|
|
if ($self->cd) { |
39
|
0
|
|
|
|
|
|
$uri->query_form(cd => $self->cd); |
40
|
|
|
|
|
|
|
} |
41
|
0
|
0
|
|
|
|
|
if ($self->type) { |
42
|
0
|
|
|
|
|
|
$uri->query_form(type => $self->type); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
my $res = $self->ua->get($uri); |
45
|
0
|
0
|
|
|
|
|
croak "wrong response:". $res->status_line unless $res->is_success; |
46
|
0
|
|
|
|
|
|
my $json = $res->content; |
47
|
0
|
0
|
|
|
|
|
return $json if $raw; |
48
|
0
|
|
|
|
|
|
return decode_json($json); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub data { |
52
|
0
|
|
|
0
|
1
|
|
my ($self, $domain, $delimi) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
unless (defined $delimi) { |
55
|
0
|
|
|
|
|
|
$delimi = "\n"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $hash = $self->resolve($domain); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return join($delimi, map { $_->{data} } @{$hash->{Answer}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |