Many/Mapquest.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
_MIN_MODULE_VERSION
2.0
geocode
2.0
_determine_precision
2.0
CRAP 2.0
1 package Geo::Coder::Many::Mapquest;
2  
3 use warnings;
4 use strict;
5 use Carp;
6 use Geo::Coder::Many::Generic;
7 use base 'Geo::Coder::Many::Generic';
8  
9 =head1 NAME
10  
11 Geo::Coder::Many::Mapquest - Mapquest plugin Geo::Coder::Many
12  
13 =head1 VERSION
14  
15 Version 0.02
16  
17 =cut
18  
19 our $VERSION = '0.02';
20  
21 # Requires Geo::Coder::Mapquest 0.05 or above
22 sub _MIN_MODULE_VERSION { return '0.05'; }
23  
24 =head1 SYNOPSIS
25  
26 This module adds Mapquest support to Geo::Coder::Many.
27  
28 Use as follows:
29  
30 use Geo::Coder::Many;
31 use Geo::Coder::Mapquest;
32
33 my $options = { };
34 my $geocoder_many = Geo::Coder::Many->new( $options );
35 my $MQ = Geo::Coder::Mapquest->new(apikey => 'Your API key');
36
37 my $options = {
38 geocoder => $MQ,
39 };
40
41 $geocoder_many->add_geocoder( $options );
42
43 my $location = $geocoder_many->geocode(
44 {
45 location => '82 Clerkenwell Road, London, EC1M 5RF'
46 }
47 );
48  
49 =head1 MORE INFO
50  
51 please see http://search.cpan.org/dist/Geo-Coder-Mapquest/
52 and http://developer.mapquest.com/web/products/dev-services/geocoding-ws
53  
54 =head1 SUBROUTINES/METHODS
55  
56 =head2 geocode
57  
58 This is called by Geo::Coder::Many - it sends the geocoding request (via
59 Geo::Coder::Mapquest) and extracts the resulting location, returning it in a
60 standard Geo::Coder::Many::Response.
61  
62 NOTE: currently precision is hard coded to undef! We need to fix it to
63 interpret the code returned by mapquest and assigning a meaningful
64 precision
65  
66 =cut
67  
68 sub geocode {
69 my $self = shift;
70 my $location = shift;
71 defined $location or croak "Geo::Coder::Many::Mapquest::geocode
72 method must be given a location.";
73  
74 my @raw_replies = $self->{GeoCoder}->geocode( location => $location );
75 my $response = Geo::Coder::Many::Response->new( { location => $location } );
76  
77 foreach my $raw_reply ( @raw_replies ) {
78  
79  
80 # need to determine precision from response code
81 my $precision =
82 $self->_determine_precision($raw_reply->{geocodeQualityCode});
83  
84 my $tmp = {
85 address => $raw_reply->{display_name},
86 country => $raw_reply->{adminArea1},
87 longitude => $raw_reply->{latLng}->{lng},
88 latitude => $raw_reply->{latLng}->{lat},
89 precision => $precision,
90 };
91 $response->add_response( $tmp, $self->get_name() );
92 }
93  
94 my $http_response = $self->{GeoCoder}->response();
95 $response->set_response_code($http_response->code());
96 return $response;
97 }
98  
99 sub _determine_precision {
100 my $self = shift;
101 my $code = shift;
102  
103 my $precision = undef; # FIXME!
104 # for now all precision set to undef (ie we dont know)
105 # should instead be converting to meaningful number between 0 and 1
106 # based on code
107 # see http://www.mapquestapi.com/geocoding/geocodequality.html
108 return $precision;
109 }
110  
111 =head2 get_name
112  
113 Returns the name of the geocoder type - used by Geo::Coder::Many
114  
115 =cut
116  
117 sub get_name { my $self = shift; return 'mapquest ' . $self->{GeoCoder}->VERSION; }
118  
119 1;
120  
121 __END__