| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 6 |  |  | 6 |  | 179408 | use 5.014; | 
|  | 6 |  |  |  |  | 46 |  | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 6 |  |  | 6 |  | 25 | use strict; | 
|  | 6 |  |  |  |  | 9 |  | 
|  | 6 |  |  |  |  | 96 |  | 
| 4 | 6 |  |  | 6 |  | 21 | use warnings; | 
|  | 6 |  |  |  |  | 7 |  | 
|  | 6 |  |  |  |  | 234 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | package WebService::Geocodio; | 
| 7 |  |  |  |  |  |  | $WebService::Geocodio::VERSION = '0.05'; | 
| 8 | 6 |  |  | 6 |  | 2575 | use Moo; | 
|  | 6 |  |  |  |  | 62955 |  | 
|  | 6 |  |  |  |  | 22 |  | 
| 9 | 6 |  |  | 6 |  | 9146 | use strictures 2; | 
|  | 6 |  |  |  |  | 7553 |  | 
|  | 6 |  |  |  |  | 178 |  | 
| 10 | 6 |  |  | 6 |  | 924 | use Carp qw(confess); | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 235 |  | 
| 11 | 6 |  |  | 6 |  | 30 | use Scalar::Util qw(blessed); | 
|  | 6 |  |  |  |  | 8 |  | 
|  | 6 |  |  |  |  | 3040 |  | 
| 12 |  |  |  |  |  |  | with('WebService::Geocodio::Request'); | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | # ABSTRACT: A Perl interface to Geocod.io | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has 'api_key' => ( | 
| 19 |  |  |  |  |  |  | is => 'ro', | 
| 20 |  |  |  |  |  |  | isa => sub { confess "$_[0] doesn't look like a valid api key\n" unless $_[0] =~ /[0-9a-f]+/ }, | 
| 21 |  |  |  |  |  |  | required => 1, | 
| 22 |  |  |  |  |  |  | ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | has 'locations' => ( | 
| 26 |  |  |  |  |  |  | is => 'rw', | 
| 27 |  |  |  |  |  |  | default => sub { [] }, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | has 'fields' => ( | 
| 32 |  |  |  |  |  |  | is => 'rw', | 
| 33 |  |  |  |  |  |  | predicate => 1, | 
| 34 |  |  |  |  |  |  | default => sub { [] }, | 
| 35 |  |  |  |  |  |  | ); | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub add_location { | 
| 39 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 |  |  |  |  |  | push @{ $self->locations }, @_; | 
|  | 0 |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub show_locations { | 
| 46 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 0 |  |  |  |  |  | return @{ $self->locations }; | 
|  | 0 |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub clear_locations { | 
| 53 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 0 |  |  |  |  |  | $self->locations([]); | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub add_field { | 
| 60 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 0 |  |  |  |  |  | push @{ $self->fields }, grep { /cd|cd113|cd114|cd115|stateleg|timezone|school|census/ } @_; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | sub geocode { | 
| 67 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 0 | 0 |  |  |  |  | $self->add_location(@_) if scalar @_; | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 0 | 0 |  |  |  |  | return undef if scalar @{$self->locations} < 1; | 
|  | 0 |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 0 |  |  |  |  |  | my @r = $self->send_forward( $self->_format('forward') ); | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 0 | 0 |  |  |  |  | wantarray ? return @r : return \@r; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub reverse_geocode { | 
| 80 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 0 | 0 |  |  |  |  | $self->add_location(@_) if scalar @_; | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 0 | 0 |  |  |  |  | return undef if scalar @{$self->locations} < 1; | 
|  | 0 |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 0 |  |  |  |  |  | my @r = $self->send_reverse( $self->_format('reverse') ); | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 0 | 0 |  |  |  |  | wantarray ? return @r : return \@r; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | sub _format { | 
| 92 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 93 | 0 |  |  |  |  |  | my $direction = shift; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 0 | 0 |  |  |  |  | my $method = $direction eq 'forward' ? '_forward_formatting' | 
| 96 |  |  |  |  |  |  | : '_reverse_formatting'; | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 0 | 0 |  |  |  |  | return [ map {; blessed $_ ? $_->$method : $_ } @{$self->locations} ]; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | 1; | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | __END__ |