Skip Menu |

This queue is for tickets about the Geo-Cloudmade CPAN distribution.

Report information
The Basics
Id: 84811
Status: resolved
Priority: 0/
Queue: Geo-Cloudmade

People
Owner: Nobody in particular
Requestors: TIMB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] performance, feature and bug fix patch
Hi Dmytro. I've attached a patch that does the following: - Enable the UserAgent connection cache - Caches the UserAgent object, so the connection cache is effective - Fixes 'error' being persistent across requests - Adds a http_status method to give access to the http status code - Also sanity checks that the centroid type is a POINT Thanks for Geo::Cloudmade! Tim.
Subject: geo-cloudmade-0-06.patch
commit 24c364b8aaa5704a190b6e3dc405f4f0dd7a0d6f Author: Tim Bunce <Tim.Bunce@pobox.com> Date: Tue Apr 23 09:37:23 2013 -0500 Patches to Geo::Cloudmade (which should be sent upstream) Cache the user agent. Enable connection caching. Make the http status code available. Return undef, not empty list, on error. return undef if centroid type is not POINT. diff --git a/cpan/lib/perl5/Geo/Cloudmade.pm b/cpan/lib/perl5/Geo/Cloudmade.pm index 56f68e0..f0d4405 100644 --- a/cpan/lib/perl5/Geo/Cloudmade.pm +++ b/cpan/lib/perl5/Geo/Cloudmade.pm @@ -75,7 +75,7 @@ use JSON; use Math::Trig; use constant HOST => 'cloudmade.com'; -use constant DEBUG => 0; +use constant DEBUG => $ENV{GEO_CLOUDMADE_DEBUG}; =head1 CONSTRUCTOR @@ -89,7 +89,12 @@ use constant DEBUG => 0; =cut sub new { my ($class, $key) = @_; - bless { key => $key, error => '' }, $class + bless { + key => $key, + ua => LWP::UserAgent->new( keep_alive => 2 ), + error => '', + http_status => 0, + }, $class } # internal method @@ -104,16 +109,17 @@ sub call_service { $uri->query_form($params); print "uri=", $uri->as_string, "\n" if DEBUG; - my $useragent = new LWP::UserAgent; my $request = new HTTP::Request(GET => $uri->as_string); - my $response = $useragent->request($request); + my $response = $self->{ua}->request($request); + $self->{http_status} = $response->code; if ($response->is_success) { + $self->{error} = ''; return $response->content; } else { $self->{error} = "HTTP request error: ".$response->status_line."\n"; - return (); + return undef; } } @@ -233,6 +239,7 @@ sub get_tile { } sub error { $_[0]->{error} } +sub http_status { $_[0]->{http_status} } package Geo::Cloudmade::Route; =head1 Geo::Cloudmade::Route @@ -270,6 +277,7 @@ sub properties { @{$this->{properties}}{@names}; } sub centroid { + return undef unless $_[0]->{centroid}{type} eq 'POINT'; bless $_[0]->{centroid}{coordinates}, 'Geo::Cloudmade::Point' } package Geo::Cloudmade::Point;
Done, thanks for using Geo::Cloudmade and the patch. On Tue Apr 23 14:59:03 2013, TIMB wrote: Show quoted text
> Hi Dmytro. > > I've attached a patch that does the following: > > - Enable the UserAgent connection cache > - Caches the UserAgent object, so the connection cache is effective > - Fixes 'error' being persistent across requests > - Adds a http_status method to give access to the http status code > - Also sanity checks that the centroid type is a POINT > > Thanks for Geo::Cloudmade! > > Tim.