blib/lib/Astro/App/Satpass2/Geocode/OSM.pm

filter: Statementstmt 48.2% 27 / 56 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 8 / 12 Podpod 100% 1 / 1 totaltotal 40.9% 36 / 88 CC 8 SCAR 20.5
CC
8
Cov
38%
__ANON__
20.0
geocode
12.0
_field
6.0
CRAP 7.8
« blib/lib/Astro/App/Satpass2/FormatValue.pm ↑ Summary blib/lib/Astro/App/Satpass2/ParseTime/Code.pm »
1 package Astro::App::Satpass2::Geocode::OSM;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use parent qw{ Astro::App::Satpass2::Geocode };
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Astro::App::Satpass2::Utils qw{ instance @CARP_NOT };
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '0.059';
14  
15 1 ▶use constant GEOCODER_CLASS => 'Geo::Coder::OSM';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use constant GEOCODER_SITE => 'http://nominatim.openstreetmap.org/';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub geocode {
Subroutine geocode: not called CC=3 SCAR=24.8
Pod documented
20 0 my ( $self, $loc ) = @_;
21  
22 0 my $geocoder = $self->geocoder();
23  
24 0 ▶ if ( my @rslt = $geocoder->geocode( location => $loc ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@rslt) = $geocoder->geocode('location', $loc)) { } 0 0 0
25 # Heuristic to prevent cruft being returned.
26 0 ▶ if ( @rslt > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rslt > 1) 0 0 0
27 0 my $cutoff = List::Util::max( map { $_->{importance} }
28 @rslt ) - 0.3;
29 0 @rslt = grep { $_->{importance} > $cutoff } @rslt;
30 }
31 return (
32 map {
33 0 {
34 ## country => uc $_->{address}{country_code},
35 description => _description( $_ ),
36 latitude => $_->{lat},
37 longitude => $_->{lon},
38 }
39 0 } @rslt );
40 } else {
41 0 return $self->__geocode_failure();
42 }
43  
44 }
45  
46 {
47 my $desc = {
48 0 ▶ us => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
49 0 my ( $info ) = @_;
50 0 my $addr = $info->{address};
51 0 ▶ my @field = (
Branch: 1 branch
BranchTrueFalseTotal
my(@field) = (_field($addr, ("house_number", "pedestrian")) || _field($addr, ("house_number", "road")) || _field($addr, "road"), _field($addr, "city"), _field($addr, "state")) or return 0 0 0
Condition0%0/6
_field($addr, ('house_number', 'pedestrian')) || _field($addr, ('house_number', 'road')) || _field($addr, 'road')
l!l&&r!l&&!r
000
_field($addr, ("house_number", "pedestrian")) or _field($addr, ("house_number", "road"))
l!l&&r!l&&!r
000
MC/DC0%0/3
_field($addr, ('house_number', 'pedestrian')) || _field($addr, ('house_number', 'road')) || _field($addr, 'road')
_field($addr, ("house_number", "pedestrian")) _field($addr, ("house_number", "road")) _field($addr, 'road')
Truth table0%0/4
A or B || C
A= _field($addr, ("house_number", "pedestrian"))B= _field($addr, ("house_number", "road"))C= _field($addr, 'road')
ABCresult
1XX1
01X1
0011
0000
52 _field( $addr, qw{ house_number pedestrian } ) ||
53 _field( $addr, qw{ house_number road } ) ||
54 _field( $addr, 'road' ),
55 _field( $addr, 'city' ),
56 _field( $addr, 'state' ),
57 ) or return;
58 0 $field[-1] .= ' USA';
59 0 return join ', ', @field;
60 },
61 1 };
62  
63 0 ▶ sub _field {
Subroutine _field: not called CC=2 SCAR=17.9
64 0 my ( $addr, @items ) = @_;
65 0 @items == grep { defined $addr->{$_} } @items
66 0 ▶ and return join ' ', map { $addr->{$_} } @items;
Branch: 1 branch
BranchTrueFalseTotal
@items == grep({defined $addr->{$_};} @items) and return join(" ", map({$addr->{$_};} @items)) 0 0 0
67 0 return;
68 }
69  
70 0 ▶ sub _description {
Subroutine _description: not called CC=2 SCAR=17.9
71 0 my ( $info ) = @_;
72 0 my $country = lc $info->{address}{country_code};
73 0 ▶ if ( my $code = $desc->{$country} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $desc->{$country}) { } 0 0 0
74 0 return $code->( $info );
75 } else {
76 0 my $desc = $info->{display_name};
77 0 $desc =~ s/ [^,]+ , \s* //smx;
78 0 $desc =~ s/ \A ( [0-9]+ ) , /$1/smx; # Oh, for 5.10 and \K
79 0 return $desc;
80 }
81 }
82 }
83  
84 1 1;
85  
86 __END__
« blib/lib/Astro/App/Satpass2/FormatValue.pm ↑ Summary blib/lib/Astro/App/Satpass2/ParseTime/Code.pm »