Geocodio/Location.pm

filter: Statementstmt 88.3% 53 / 60 Branchbran 73.3% 22 / 30 Conditioncond 50.0% 9 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 73.4% 94 / 128 CC 22 SCAR 22.9
CC
22
Cov
78%
_forward_formatting
14.4
_reverse_formatting
12.0
BUILDARGS
8.2
CRAP 9.8
« Geocodio/Fields.pm ↑ Summary Geocodio.pm »
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
BranchTrueFalseTotal
if (ref $args[0] eq 'HASH') { } 2 5 7
elsif (@args % 2 == 1) { } 1 4 5
25 2 my $hr = $args[0];
26 2 ▶ $out->{accuracy} = $hr->{accuracy} if exists $hr->{accuracy};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hr->{"accuracy"} 2 0 2
27 2 ▶ $out->{formatted} = $hr->{formatted_address} if exists $hr->{formatted_address};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hr->{"formatted_address"} 2 0 2
28 2 ▶ $out->{fields} = WebService::Geocodio::Fields->new($hr->{fields}) if exists $hr->{fields};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hr->{"fields"} 0 2 2
29 2 ▶ map { $out->{$_} = $hr->{address_components}->{$_} if exists $hr->{address_components}->{$_} } qw(number street suffix postdirection city state zip);
Branch: 1 branch
BranchTrueFalseTotal
if exists $hr->{"address_components"}{$_} 12 2 14
30 2 ▶ map { $out->{$_} = $hr->{location}->{$_} if exists $hr->{location}->{$_} } qw(lat lng);
Branch: 1 branch
BranchTrueFalseTotal
if exists $hr->{"location"}{$_} 4 0 4
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
BranchTrueFalseTotal
if $self->has_formatted 3 4 7
46  
47 4 ▶ if ( ( not $self->has_zip ) && ( not ( $self->has_city && $self->has_state ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_zip or $self->has_city and $self->has_state) 0 4 4
Condition50%3/6
$self->has_zip or $self->has_city and $self->has_state
l!l&&r!l&&!r
220
$self->has_city and $self->has_state
!ll&&!rl&&r
002
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
ABCresult
1XX1
0111
00X0
0100
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
BranchTrueFalseTotal
if ($self->has_number and $self->has_street and $self->suffix) 1 3 4
Condition66%4/6
$self->has_number and $self->has_street and $self->suffix
!ll&&!rl&&r
301
$self->has_number and $self->has_street
!ll&&!rl&&r
301
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
ABCresult
0XX0
10X0
1100
1111
53 1 my @f;
54 1 ▶ if ( $self->has_postdirection ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_postdirection) { } 1 0 1
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
BranchTrueFalseTotal
if ($self->has_city and $self->has_state) 3 1 4
Condition66%2/3
$self->has_city and $self->has_state
!ll&&!rl&&r
103
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
ABresult
0X0
100
111
66 3 $s .= join ", ", (map {; $self->$_ } qw(city state));
67 3 ▶ $s .= " " if ( $self->has_zip );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_zip 1 2 3
68 }
69  
70 4 ▶ if ( $self->has_zip ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_zip) 2 2 4
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
BranchTrueFalseTotal
unless ($self->has_lat and $self->has_lng) 0 0 0
Condition0%0/3
$self->has_lat and $self->has_lng
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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__
« Geocodio/Fields.pm ↑ Summary Geocodio.pm »