| 1 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package WebService::Geocodio::Location; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | $WebService::Geocodio::Location::VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use WebService::Geocodio::Fields; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Location object for use with Geocod.io service. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | has [qw(number street suffix postdirection city state zip formatted lat lng accuracy fields)] => ( | |||||||||||||||||||||||||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | if (ref($args[0]) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my $hr = $args[0]; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | $out->{accuracy} = $hr->{accuracy} if exists $hr->{accuracy}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | $out->{formatted} = $hr->{formatted_address} if exists $hr->{formatted_address}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | $out->{fields} = WebService::Geocodio::Fields->new($hr->{fields}) if exists $hr->{fields}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | map { $out->{$_} = $hr->{address_components}->{$_} if exists $hr->{address_components}->{$_} } qw(number street suffix postdirection city state zip); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | map { $out->{$_} = $hr->{location}->{$_} if exists $hr->{location}->{$_} } qw(lat lng); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | elsif ( @args % 2 == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $out->{formatted} = $args[0]; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | $out = { @args }; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 7 | ▶ | sub _forward_formatting { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_forward_formatting: called CC=13 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | return $self->formatted if $self->has_formatted; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | ▶ | if ( ( not $self->has_zip ) && ( not ( $self->has_city && $self->has_state ) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$self->has_zip or $self->has_city and $self->has_state
$self->has_city and $self->has_state
MC/DC0%0/3
$self->has_zip or $self->has_city and $self->has_state
$self->has_zip
$self->has_city
$self->has_state
Truth table50%2/4
A or B and C
A= $self->has_zipB= $self->has_cityC= $self->has_state
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | confess "A zip or city-state pair is required.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | my $s; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | if ( $self->has_number && $self->has_street && $self->suffix ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->has_number and $self->has_street and $self->suffix
$self->has_number and $self->has_street
MC/DC33%1/3
$self->has_number and $self->has_street and $self->suffix
$self->has_number
$self->has_street
$self->suffix
Truth table50%2/4
A and B and C
A= $self->has_numberB= $self->has_streetC= $self->suffix
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my @f; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | if ( $self->has_postdirection ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | @f = qw(number postdirection street suffix); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | @f = qw(number street suffix); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $s .= join " ", (map {; $self->$_ } @f); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $s .= ", "; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | if ( $self->has_city && $self->has_state) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->has_city and $self->has_state
MC/DC50%1/2
$self->has_city and $self->has_state
$self->has_city
$self->has_state
Truth table66%2/3
A and B
A= $self->has_cityB= $self->has_state
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | $s .= join ", ", (map {; $self->$_ } qw(city state)); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | $s .= " " if ( $self->has_zip ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | if ( $self->has_zip ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | $s .= $self->zip | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub _reverse_formatting { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reverse_formatting: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( not ( $self->has_lat && $self->has_lng ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->has_lat and $self->has_lng
MC/DC0%0/2
$self->has_lat and $self->has_lng
$self->has_lat
$self->has_lng
Truth table0%0/3
A and B
A= $self->has_latB= $self->has_lng
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | confess "lat-lng pair is required\n"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return join ",", ( map {; $self->$_ } qw(lat lng) ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||