| 1 | package DDG::Location; | ||||||||||||||||||||||||
| 2 | 12 | our $AUTHORITY = 'cpan:DDG'; | |||||||||||||||||||||||
| 3 | # ABSTRACT: A location, can be empty (given by Geo::IP::Record) | ||||||||||||||||||||||||
| 4 | 12 | $DDG::Location::VERSION = '1016'; | |||||||||||||||||||||||
| 5 | 12 | ▶ | use Moo; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | 12 | 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 | 12 | my @geo_ip_record_s = (@geo_ip_record_attrs, 'loc_str'); | |||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||
| 13 | sub new_from_geo_ip_record { | ||||||||||||||||||||||||
| 14 | 0 | ▶ | my ( $class, $geo_ip_record ) = @_; | ||||||||||||||||||||||
|
Subroutine
new_from_geo_ip_record: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 0 | ▶ | if ($geo_ip_record) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 17 | 0 | my %args; | |||||||||||||||||||||||
| 18 | 0 | for (@geo_ip_record_attrs) { | |||||||||||||||||||||||
| 19 | 0 | ▶ | $args{$_} = $geo_ip_record->$_ if defined $geo_ip_record->$_; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||
| 22 | # add short location summary string: postal_code if it exists, otherwise 'city, country' or 'region, country' | ||||||||||||||||||||||||
| 23 | 0 | ▶ | my $city = $geo_ip_record->city || $geo_ip_record->region_name; | ||||||||||||||||||||||
|
Condition0%0/3
$geo_ip_record->city || $geo_ip_record->region_name
MC/DC0%0/2
$geo_ip_record->city || $geo_ip_record->region_name
$geo_ip_record->city
$geo_ip_record->region_name
Truth table0%0/3
A || B
A= $geo_ip_record->cityB= $geo_ip_record->region_name
| |||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||
| 25 | 0 | ▶ | if ($city) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 26 | 0 | ▶ | $city .= ', ' . $geo_ip_record->country_name if $geo_ip_record->country_name; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||
| 29 | 0 | ▶ | $args{loc_str} = $geo_ip_record->postal_code || $city || ''; | ||||||||||||||||||||||
|
Condition0%0/5
$geo_ip_record->postal_code || $city || ''
$geo_ip_record->postal_code or $city
MC/DC0%0/2
$geo_ip_record->postal_code || $city || ''
$geo_ip_record->postal_code
$city
Truth table0%0/3
A or B
A= $geo_ip_record->postal_codeB= $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 | 395 | ▶ | default => sub { '' } | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 43 | 12 | ) for (@geo_ip_record_s); | |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | 12 | has geo_ip_record => ( | |||||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||||
| 47 | predicate => 'has_geo_ip_record', | ||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||
| 50 | use overload '""' => sub { | ||||||||||||||||||||||||
| 51 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 52 | 0 | return $self->country_code; | |||||||||||||||||||||||
| 53 | 12 | ▶ | }, fallback => 1; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | 12 | 1; | |||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||