line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
19357
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
4
|
|
|
|
|
|
|
package Net::DNS::GuessTZ; |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$Net::DNS::GuessTZ::VERSION = '0.004'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: guess the time zone of a host |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
984
|
use DateTime::TimeZone 0.51; |
|
1
|
|
|
|
|
59221
|
|
|
1
|
|
|
|
|
29
|
|
12
|
1
|
|
|
1
|
|
12
|
use List::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
943
|
use Sub::Exporter::Util; |
|
1
|
|
|
|
|
6226
|
|
|
1
|
|
|
|
|
7
|
|
15
|
1
|
|
|
|
|
4
|
use Sub::Exporter -setup => { |
16
|
|
|
|
|
|
|
exports => [ tz_from_host => Sub::Exporter::Util::curry_method ], |
17
|
1
|
|
|
1
|
|
169
|
}; |
|
1
|
|
|
|
|
2
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $ICF; |
20
|
|
|
|
|
|
|
sub _icf { |
21
|
0
|
|
0
|
0
|
|
0
|
$ICF ||= do { |
22
|
0
|
|
|
|
|
0
|
require IP::Country::Fast; |
23
|
0
|
|
|
|
|
0
|
IP::Country::Fast->new; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _all_tz_from_cctld { |
28
|
0
|
|
|
0
|
|
0
|
my ($self, $host) = @_; |
29
|
0
|
0
|
|
|
|
0
|
return unless my ($cctld) = $host =~ /\.(\w{2})\z/; |
30
|
0
|
|
|
|
|
0
|
DateTime::TimeZone->names_in_country($cctld); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _all_tz_from_ip { |
34
|
0
|
|
|
0
|
|
0
|
my ($self, $host) = @_; |
35
|
0
|
0
|
|
|
|
0
|
return unless my $cc = $self->_icf->inet_atocc($host); |
36
|
0
|
|
|
|
|
0
|
my @names = DateTime::TimeZone->names_in_country($cc); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub tz_from_host { |
41
|
2
|
|
|
2
|
1
|
16
|
my ($self, $host, $arg) = @_; |
42
|
2
|
50
|
|
|
|
14
|
return unless $host; |
43
|
0
|
|
0
|
|
|
|
$arg ||= {}; |
44
|
0
|
0
|
|
|
|
|
$arg->{ip_country} = 1 unless exists $arg->{ip_country}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my %result; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my @names = $self->_all_tz_from_cctld($host); |
49
|
0
|
0
|
|
|
|
|
$result{cc} = $names[0] if @names; # and @names <= 3; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($arg->{ip_country}) { |
52
|
0
|
|
|
|
|
|
my @names = $self->_all_tz_from_ip($host); |
53
|
0
|
0
|
|
|
|
|
$result{ip} = $names[0] if @names; # if @names <= 3; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
0
|
|
|
|
my @cand = ($arg->{priority}||'ip') eq 'cc' |
57
|
|
|
|
|
|
|
? @result{qw(cc ip)} |
58
|
|
|
|
|
|
|
: @result{qw(ip cc)}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
0
|
|
|
if (my $tz = List::Util::first { defined } @cand) { |
|
0
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $tz; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |