File Coverage

lib/Geo/Coder/Many/Bing.pm
Criterion Covered Total %
statement 9 23 39.1
branch n/a
condition n/a
subroutine 3 6 50.0
pod 2 2 100.0
total 14 31 45.1


line stmt bran cond sub pod time code
1             package Geo::Coder::Many::Bing;
2              
3 2     2   7 use strict;
  2         3  
  2         53  
4 2     2   5 use warnings;
  2         2  
  2         59  
5              
6 2     2   8 use base 'Geo::Coder::Many::Generic';
  2         3  
  2         640  
7              
8             =head1 NAME
9              
10             Geo::Coder::Many::Bing - Plugin for the Bing geocoder
11              
12             =head1 VERSION
13              
14             Version 0.02
15              
16             =cut
17              
18             our $VERSION = '0.02';
19              
20             # Requires Geo::Coder::Bing 0.10 or above
21 0     0     sub _MIN_MODULE_VERSION { return '0.10'; }
22              
23             =head1 SYNOPSIS
24              
25             This class wraps Geo::Coder::Bing such that it can be used in
26             Geo::Coder::Many, by converting the results to a standard form.
27              
28             Requires Geo::Coder::Bing >= 0.10
29              
30             =head1 METHODS
31              
32             =head2 geocode
33              
34             Takes a location string, geocodes it using Geo::Coder::Bing, and returns the
35             result in a form understandable to Geo::Coder::Many
36              
37             =cut
38              
39             sub geocode {
40 0     0 1   my $self = shift;
41 0           my $location = shift;
42              
43 0           my @raw_replies = $self->{GeoCoder}->geocode( location => $location );
44              
45 0           my $http_response = $self->{GeoCoder}->response();
46              
47 0           my $Response = Geo::Coder::Many::Response->new( { location => $location } );
48              
49 0           my %convert = (
50             'High' => 0.9,
51             'Medium' => 0.5,
52             'Low' => 0.1,
53             'Unknown' => undef,
54             );
55              
56 0           foreach my $raw_reply (@raw_replies) {
57              
58             my $tmp = {
59             address => $raw_reply->{address}->{formattedAddress},
60             country => $raw_reply->{address}->{countryRegion},
61             latitude => $raw_reply->{point}->{coordinates}->[0],
62             longitude => $raw_reply->{point}->{coordinates}->[1],
63             precision => $convert{$raw_reply->{confidence}},
64 0           };
65 0           $Response->add_response( $tmp, $self->get_name());
66             }
67              
68 0           $Response->set_response_code($http_response->code());
69 0           return $Response;
70             }
71              
72             =head2 get_name
73              
74             The short name by which Geo::Coder::Many can refer to this geocoder.
75              
76             =cut
77              
78 0     0 1   sub get_name { my $self = shift; return 'bing ' . $self->{GeoCoder}->VERSION; }
  0            
79              
80             1;
81              
82             __END__