line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DDG::Location; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:DDG'; |
3
|
|
|
|
|
|
|
# ABSTRACT: A location, can be empty (given by Geo::IP::Record) |
4
|
|
|
|
|
|
|
$DDG::Location::VERSION = '1016'; |
5
|
12
|
|
|
12
|
|
794
|
use Moo; |
|
12
|
|
|
|
|
14134
|
|
|
12
|
|
|
|
|
362
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my @geo_ip_record_attrs = qw( country_code country_code3 country_name region |
8
|
|
|
|
|
|
|
region_name city postal_code latitude longitude time_zone area_code |
9
|
|
|
|
|
|
|
continent_code metro_code ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my @geo_ip_record_s = (@geo_ip_record_attrs, 'loc_str'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new_from_geo_ip_record { |
14
|
0
|
|
|
0
|
0
|
|
my ( $class, $geo_ip_record ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
if ($geo_ip_record) { |
17
|
0
|
|
|
|
|
|
my %args; |
18
|
0
|
|
|
|
|
|
for (@geo_ip_record_attrs) { |
19
|
0
|
0
|
|
|
|
|
$args{$_} = $geo_ip_record->$_ if defined $geo_ip_record->$_; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# add short location summary string: postal_code if it exists, otherwise 'city, country' or 'region, country' |
23
|
0
|
|
0
|
|
|
|
my $city = $geo_ip_record->city || $geo_ip_record->region_name; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if ($city) { |
26
|
0
|
0
|
|
|
|
|
$city .= ', ' . $geo_ip_record->country_name if $geo_ip_record->country_name; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
0
|
|
|
|
$args{loc_str} = $geo_ip_record->postal_code || $city || ''; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $class->new( |
32
|
|
|
|
|
|
|
geo_ip_record => $geo_ip_record, |
33
|
|
|
|
|
|
|
%args, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
|
return $class->new; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has $_ => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
default => sub { '' } |
43
|
|
|
|
|
|
|
) for (@geo_ip_record_s); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has geo_ip_record => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
predicate => 'has_geo_ip_record', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use overload '""' => sub { |
51
|
0
|
|
|
0
|
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
return $self->country_code; |
53
|
12
|
|
|
12
|
|
7984
|
}, fallback => 1; |
|
12
|
|
|
|
|
1547
|
|
|
12
|
|
|
|
|
109
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |