r73950 - in /branches/upstream/libgeo-coder-googlev3-perl: ./ current/ current/lib/ current/lib/Geo/ current/lib/Geo/Coder/ current/t/
emhn-guest at users.alioth.debian.org
emhn-guest at users.alioth.debian.org
Tue May 3 21:23:18 UTC 2011
Author: emhn-guest
Date: Tue May 3 21:23:00 2011
New Revision: 73950
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=73950
Log:
[svn-inject] Installing original source of libgeo-coder-googlev3-perl (0.07)
Added:
branches/upstream/libgeo-coder-googlev3-perl/
branches/upstream/libgeo-coder-googlev3-perl/current/
branches/upstream/libgeo-coder-googlev3-perl/current/.gitignore
branches/upstream/libgeo-coder-googlev3-perl/current/Changes
branches/upstream/libgeo-coder-googlev3-perl/current/MANIFEST
branches/upstream/libgeo-coder-googlev3-perl/current/META.yml
branches/upstream/libgeo-coder-googlev3-perl/current/Makefile.PL
branches/upstream/libgeo-coder-googlev3-perl/current/README
branches/upstream/libgeo-coder-googlev3-perl/current/lib/
branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/
branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/Coder/
branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/Coder/Googlev3.pm
branches/upstream/libgeo-coder-googlev3-perl/current/t/
branches/upstream/libgeo-coder-googlev3-perl/current/t/geocode.t
Added: branches/upstream/libgeo-coder-googlev3-perl/current/.gitignore
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/.gitignore?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/.gitignore (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/.gitignore Tue May 3 21:23:00 2011
@@ -1,0 +1,6 @@
+/.prove
+/Geo-Coder-Googlev3-*.tar.gz
+/Makefile
+/Makefile.old
+/blib
+/pm_to_blib
Added: branches/upstream/libgeo-coder-googlev3-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/Changes?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/Changes (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/Changes Tue May 3 21:23:00 2011
@@ -1,0 +1,25 @@
+Revision history for Perl extension Geo::Coder::Googlev3.
+
+0.07
+ - ZERO_RESULTS is not anymore an error, but is returned as an
+ empty result
+ - raw option
+
+0.06
+ - more diagnostics if an API call failed (status!=OK)
+
+0.05
+ - geocode method now returns multiple results in list context
+
+0.04
+ - just another test fix
+
+0.03
+ - fixed test to accommodate changed results from Google
+
+0.02
+ - more Pod
+ - more tests (region-specific)
+
+0.01
+ - first working version
Added: branches/upstream/libgeo-coder-googlev3-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/MANIFEST?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/MANIFEST (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/MANIFEST Tue May 3 21:23:00 2011
@@ -1,0 +1,8 @@
+.gitignore
+Changes
+lib/Geo/Coder/Googlev3.pm
+Makefile.PL
+MANIFEST This list of files
+README
+t/geocode.t
+META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libgeo-coder-googlev3-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/META.yml?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/META.yml (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/META.yml Tue May 3 21:23:00 2011
@@ -1,0 +1,27 @@
+--- #YAML:1.0
+name: Geo-Coder-Googlev3
+version: 0.07
+abstract: Google Maps v3 Geocoding API
+author:
+ - Slaven Rezic <srezic at cpan.org>
+license: perl
+distribution_type: module
+configure_requires:
+ ExtUtils::MakeMaker: 0
+build_requires:
+ ExtUtils::MakeMaker: 0
+requires:
+ Encode: 0
+ JSON::XS: 0
+ LWP::UserAgent: 0
+ URI: 0
+resources:
+ repository: git://github.com/eserte/Geo-Coder-Googlev3.git
+no_index:
+ directory:
+ - t
+ - inc
+generated_by: ExtUtils::MakeMaker version 6.56
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Added: branches/upstream/libgeo-coder-googlev3-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/Makefile.PL?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/Makefile.PL (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/Makefile.PL Tue May 3 21:23:00 2011
@@ -1,0 +1,48 @@
+use strict;
+use 5.6.0;
+use ExtUtils::MakeMaker;
+
+my $is_devel_host = defined $ENV{USER} && $ENV{USER} eq 'eserte' && $^O =~ /bsd/i && -f "../../perl.release.mk";
+my $eumm_recent_enough = $ExtUtils::MakeMaker::VERSION >= 6.54;
+
+if (!$eumm_recent_enough) {
+ *MY::dist_core = sub {
+ <<'EOF';
+dist :
+ $(NOECHO) $(ECHO) "Sorry, use a newer EUMM!"
+
+EOF
+ };
+}
+
+WriteMakefile(
+ NAME => 'Geo::Coder::Googlev3',
+ VERSION_FROM => 'lib/Geo/Coder/Googlev3.pm',
+ PREREQ_PM => {
+ 'Encode' => 0,
+ 'JSON::XS' => 0,
+ 'LWP::UserAgent' => 0,
+ 'URI' => 0,
+ },
+ LICENSE => 'perl',
+ ($] >= 5.005 ?
+ (ABSTRACT_FROM => 'lib/Geo/Coder/Googlev3.pm',
+ AUTHOR => 'Slaven Rezic <srezic at cpan.org>') : ()),
+ ($eumm_recent_enough ?
+ (META_ADD => { resources => { repository => 'git://github.com/eserte/Geo-Coder-Googlev3.git' } }) : ()),
+);
+
+sub MY::postamble {
+ my $postamble = '';
+
+ if ($is_devel_host) {
+ $postamble .= <<'EOF';
+
+.include "../../perl.release.mk"
+.include "../../perl.git.mk"
+
+EOF
+ }
+
+ $postamble;
+}
Added: branches/upstream/libgeo-coder-googlev3-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/README?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/README (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/README Tue May 3 21:23:00 2011
@@ -1,0 +1,7 @@
+Geo::Coder::Googlev3
+--------------------
+
+An implementation of version 3 of Google's Geocoding API. Notable
+difference to version 2: an API key is not needed anymore.
+
+Author: Slaven Rezic
Added: branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/Coder/Googlev3.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/Coder/Googlev3.pm?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/Coder/Googlev3.pm (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/lib/Geo/Coder/Googlev3.pm Tue May 3 21:23:00 2011
@@ -1,0 +1,260 @@
+# -*- perl -*-
+
+#
+# Author: Slaven Rezic
+#
+# Copyright (C) 2010,2011 Slaven Rezic. All rights reserved.
+# This package is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+package Geo::Coder::Googlev3;
+
+use strict;
+use vars qw($VERSION);
+our $VERSION = '0.07';
+
+use Carp ('croak');
+use Encode ();
+use JSON::XS ();
+use LWP::UserAgent ();
+use URI ();
+use URI::QueryParam ();
+
+sub new {
+ my($class, %args) = @_;
+ my $self = bless {}, $class;
+ $self->{ua} = delete $args{ua} || LWP::UserAgent->new(agent => __PACKAGE__ . "/$VERSION libwww-perl/$LWP::VERSION");
+ $self->{region} = delete $args{region} || delete $args{gl};
+ $self->{language} = delete $args{language};
+ croak "Unsupported arguments: " . join(" ", %args) if %args;
+ $self;
+}
+
+sub ua {
+ my $self = shift;
+ if (@_) {
+ $self->{ua} = shift;
+ }
+ $self->{ua};
+}
+
+sub geocode {
+ my($self, %args) = @_;
+ my $loc = $args{location};
+ my $raw = $args{raw};
+ my $ua = $self->ua;
+ my $url = URI->new('http://maps.google.com/maps/api/geocode/json');
+ my %url_params;
+ $url_params{address} = $loc;
+ $url_params{sensor} = 'false';
+ $url_params{region} = $self->{region} if defined $self->{region};
+ $url_params{language} = $self->{language} if defined $self->{language};
+ while(my($k,$v) = each %url_params) {
+ $url->query_param($k => Encode::encode_utf8($v));
+ }
+ $url = $url->as_string;
+ my $resp = $ua->get($url);
+ if ($resp->is_success) {
+ my $content = $resp->decoded_content(charset => "none");
+ my $res = JSON::XS->new->utf8->decode($content);
+ if ($raw) {
+ return $res;
+ }
+ if ($res->{status} eq 'OK') {
+ if (wantarray) {
+ return @{ $res->{results} };
+ } else {
+ return $res->{results}->[0];
+ }
+ } elsif ($res->{status} eq 'ZERO_RESULTS') {
+ return;
+ } else {
+ croak "Fetching $url did not return OK status, but '" . $res->{status} . "'";
+ }
+ } else {
+ croak "Fetching $url failed: " . $resp->status_line;
+ }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Geo::Coder::Googlev3 - Google Maps v3 Geocoding API
+
+=head1 SYNOPSIS
+
+ use Geo::Coder::Googlev3;
+
+ my $geocoder = Geo::Coder::Googlev3->new;
+ my $location = $geocoder->geocode(location => 'Brandenburger Tor, Berlin');
+ my @locations = $geocoder->geocode(location => 'Berliner Straße, Berlin, Germany');
+
+=head1 DESCRIPTION
+
+Use this module just like L<Geo::Coder::Google>. Note that no
+C<apikey> is used in Google's v3 API, and the returned data structure
+differs.
+
+Please check also
+L<http://code.google.com/intl/en/apis/maps/documentation/geocoding/>
+for more information about Google's Geocoding API and especially usage
+limits.
+
+=head2 CONSTRUCTOR
+
+=over
+
+=item new
+
+ $geocoder = Geo::Coder::Googlev3->new;
+ $geocoder = Geo::Coder::Googlev3->new(language => 'de', gl => 'es');
+
+Creates a new geocoding object.
+
+The L<Geo::Coder::Google>'s C<oe> and C<apikey> parameters are not
+supported.
+
+=back
+
+=head2 METHODS
+
+=over
+
+=item geocode
+
+ $location = $geocoder->geocode(location => $location);
+ @locations = $geocoder->geocode(location => $location);
+
+Queries I<$location> to Google Maps geocoding API. In scalar context
+it returns a hash reference of the first (best matching?) location. In
+list context it returns a list of such hash references.
+
+The returned data structure looks like this:
+
+ {
+ "formatted_address" => "Brandenburger Tor, Pariser Platz 7, 10117 Berlin, Germany",
+ "types" => [
+ "point_of_interest",
+ "establishment"
+ ],
+ "address_components" => [
+ {
+ "types" => [
+ "point_of_interest",
+ "establishment"
+ ],
+ "short_name" => "Brandenburger Tor",
+ "long_name" => "Brandenburger Tor"
+ },
+ {
+ "types" => [
+ "street_number"
+ ],
+ "short_name" => 7,
+ "long_name" => 7
+ },
+ {
+ "types" => [
+ "route"
+ ],
+ "short_name" => "Pariser Platz",
+ "long_name" => "Pariser Platz"
+ },
+ {
+ "types" => [
+ "sublocality",
+ "political"
+ ],
+ "short_name" => "Mitte",
+ "long_name" => "Mitte"
+ },
+ {
+ "types" => [
+ "locality",
+ "political"
+ ],
+ "short_name" => "Berlin",
+ "long_name" => "Berlin"
+ },
+ {
+ "types" => [
+ "administrative_area_level_2",
+ "political"
+ ],
+ "short_name" => "Berlin",
+ "long_name" => "Berlin"
+ },
+ {
+ "types" => [
+ "administrative_area_level_1",
+ "political"
+ ],
+ "short_name" => "Berlin",
+ "long_name" => "Berlin"
+ },
+ {
+ "types" => [
+ "country",
+ "political"
+ ],
+ "short_name" => "DE",
+ "long_name" => "Germany"
+ },
+ {
+ "types" => [
+ "postal_code"
+ ],
+ "short_name" => 10117,
+ "long_name" => 10117
+ }
+ ],
+ "geometry" => {
+ "viewport" => {
+ "southwest" => {
+ "lat" => "52.5094785",
+ "lng" => "13.3617711"
+ },
+ "northeast" => {
+ "lat" => "52.5230586",
+ "lng" => "13.3937859"
+ }
+ },
+ "location" => {
+ "lat" => "52.5162691",
+ "lng" => "13.3777785"
+ },
+ "location_type" => "APPROXIMATE"
+ }
+ };
+
+The B<raw> option may be set to a true value to get the uninterpreted,
+raw result from the API. Just the JSON data will be translated into a
+perl hash.
+
+ $raw_result = $geocoder->geocode(location => $location, raw => 1);
+
+=back
+
+=head1 AUTHOR
+
+Slaven Rezic <srezic at cpan.org>
+
+This package is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Geo::Coder::Google>, L<Geo::Coder::Many>.
+
+=cut
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# indent-tabs-mode: nil
+# End:
+# vim:sw=4:ts=8:sta:et
Added: branches/upstream/libgeo-coder-googlev3-perl/current/t/geocode.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libgeo-coder-googlev3-perl/current/t/geocode.t?rev=73950&op=file
==============================================================================
--- branches/upstream/libgeo-coder-googlev3-perl/current/t/geocode.t (added)
+++ branches/upstream/libgeo-coder-googlev3-perl/current/t/geocode.t Tue May 3 21:23:00 2011
@@ -1,0 +1,107 @@
+# -*- coding:iso-8859-1; -*-
+
+use strict;
+use Test::More;
+
+sub within ($$$$$$);
+
+plan tests => 30;
+
+use_ok 'Geo::Coder::Googlev3';
+
+my $geocoder = Geo::Coder::Googlev3->new;
+isa_ok $geocoder, 'Geo::Coder::Googlev3';
+
+{ # list context
+ my @locations = $geocoder->geocode(location => 'Berliner Straße, Berlin, Germany');
+ cmp_ok scalar(@locations), ">", 1, "More than one result found"; # There are eight hits in Berlin, Google knows seven of them
+ like $locations[0]->{formatted_address}, qr{Berliner Straße}, 'First result looks OK';
+}
+
+{
+ my $location = $geocoder->geocode(location => 'Brandenburger Tor, Berlin, Germany');
+ like $location->{formatted_address}, qr{brandenburger tor.*berlin}i;
+ my($lat, $lng) = @{$location->{geometry}->{location}}{qw(lat lng)};
+ within $lat, $lng, 52.5, 52.6, 13.3, 13.4;
+}
+
+{ # encoding checks - bytes
+ my $location = $geocoder->geocode(location => 'Öschelbronner Weg, Berlin, Germany');
+ like $location->{formatted_address}, qr{schelbronner weg.*berlin}i;
+ my($lat, $lng) = @{$location->{geometry}->{location}}{qw(lat lng)};
+ within $lat, $lng, 52.6, 52.7, 13.3, 13.4;
+}
+
+{ # encoding checks - utf8
+ my $street = 'Öschelbronner Weg';
+ utf8::upgrade($street);
+ my $location = $geocoder->geocode(location => "$street, Berlin, Germany");
+ like $location->{formatted_address}, qr{schelbronner weg.*berlin}i;
+ my($lat, $lng) = @{$location->{geometry}->{location}}{qw(lat lng)};
+ within $lat, $lng, 52.6, 52.7, 13.3, 13.4;
+}
+
+{ # encoding checks - more utf8
+ my $street = "Trg bana Josipa Jela\x{10d}i\x{107}a";
+ my $alternative = "Ban Jela\x{10d}i\x{107} Square"; # outcome as of 2011-02-02
+ my $alternative2 = 'City of Zagreb, Croatia'; # happened once in February 2011, see http://www.cpantesters.org/cpan/report/447c31b8-6cb5-1014-b648-c13506c0976e
+ my $location = $geocoder->geocode(location => "$street, Zagreb, Croatia");
+ like $location->{formatted_address}, qr{($street|$alternative|$alternative2)}i;
+ my($lat, $lng) = @{$location->{geometry}->{location}}{qw(lat lng)};
+ within $lat, $lng, 45.8, 45.9, 15.9, 16.0;
+}
+
+{
+ my $postal_code = 'E1A 7G1';
+ my $location = $geocoder->geocode(location => "$postal_code, Canada");
+ my $postal_code_component;
+ for my $address_component (@{ $location->{address_components} }) {
+ if (grep { $_ eq 'postal_code' } @{ $address_component->{types} }) {
+ $postal_code_component = $address_component;
+ last;
+ }
+ }
+ is $postal_code_component->{long_name}, $postal_code;
+}
+
+{ # region
+ my $geocoder_es = Geo::Coder::Googlev3->new(gl => 'es', language => 'de');
+ my $location_es = $geocoder_es->geocode(location => 'Toledo');
+ is $location_es->{geometry}->{location}->{lng}, '-4.0244759';
+ my $geocoder_us = Geo::Coder::Googlev3->new();
+ my $location_us = $geocoder_us->geocode(location => 'Toledo');
+ is $location_us->{geometry}->{location}->{lng}, '-83.555212';
+}
+
+{ # zero results
+ my @locations = $geocoder->geocode(location => 'This query should not find anything but return ZERO_RESULTS, Foobartown');
+ cmp_ok scalar(@locations), "==", 0, "No result found";
+
+ my $location = $geocoder->geocode(location => 'This query should not find anything but return ZERO_RESULTS, Foobartown');
+ is $location, undef, "No result found";
+}
+
+{ # raw
+ my $raw_result = $geocoder->geocode(location => 'Brandenburger Tor, Berlin, Germany', raw => 1);
+ # This is the 11th query here, so it's very likely that the API
+ # limits are hit.
+ like $raw_result->{status}, qr{^(OK|OVER_QUERY_LIMIT)$}, 'raw query';
+ if ($raw_result->{status} eq 'OVER_QUERY_LIMIT') {
+ diag 'over query limit hit, sleep a little bit';
+ sleep 1; # in case a smoker tries this module with another perl...
+ }
+}
+
+sub within ($$$$$$) {
+ my($lat,$lng,$lat_min,$lat_max,$lng_min,$lng_max) = @_;
+ cmp_ok $lat, ">=", $lat_min;
+ cmp_ok $lat, "<=", $lat_max;
+ cmp_ok $lng, ">=", $lng_min;
+ cmp_ok $lng, "<=", $lng_max;
+}
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# End:
+# vim:ft=perl:et:sw=4
More information about the Pkg-perl-cvs-commits
mailing list