opencagedata / perl-geo-coder-opencage Goto Github PK
View Code? Open in Web Editor NEWPerl module for the OpenCage geocoding API
Home Page: https://metacpan.org/pod/Geo::Coder::OpenCage
Perl module for the OpenCage geocoding API
Home Page: https://metacpan.org/pod/Geo::Coder::OpenCage
Currently t/02-geocode.t fails with perl 5.8.x:
Can't locate feature.pm in @INC (@INC contains: ... .) at t/02-geocode.t line 4.
BEGIN failed--compilation aborted at t/02-geocode.t line 4.
t/02-geocode.t ..........
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
Probably it would pass again if say
was replaced with a normal print
, and the use feature
line removed.
You're checking that $response
is exactly a member of the HTTP::Response class, which prevents people from using user-agents that return a subclass of HTTP::Response.
Better would be:
my $content = ( blessed $response and $response->isa('HTTP::Response') )
? $response->decoded_content()
: $response->{content};
You'd need to import use Scalar::Util 'blessed';
at the top to get the blessed
keyword though.
I see that python-opencage-geocoder supports the reverse geocoding mode.
I should add that to the Perl library too!
perl-Geo-Coder-OpenCage/lib/Geo/Coder/OpenCage.pm
Lines 11 to 13 in 005cb24
You could just do:
my $version = our $VERSION;
Because our $VERSION
is set by DistZilla. However it's only set in the released version of the module, not the version which sits in your repository. So it means people wouldn't be able to run the version of your module straight from Github.
Geo::Coder::OpenCage
allows to set a user agent (ua
parameter) which defaults to HTTP::Tiny
. Documentation says "Useful if for example you want to specify that something like LWP::UserAgent::Throttled for rate limiting."
Later in code logic
my $response = $self->{ua}->get($URL);`
...
$response->{reason}
...
$response->{content}
That fits the HTTP::Tiny
interface.
But the more common LWP user agents as well, e.g. LWP::Simple
or LWP::UserAgent::Throttled
return a HTTP::Response
instance with status_line
and decoded_content
data accessors.
I suspect you mean't not to include this in the release version :-)
in new():
print Dumper $ua;
In logfiles I see
https://api.opencagedata.com/geocode/v1/json/?key=52[...]0f&limit=1&language=en&no_annotations=1&q=52.358460%2C4.881337
https://api.opencagedata.com/geocode/v1/json/?key=52[...]0f&no_annotations=1&q=55.969170%2C12.542300&limit=1&language=en
The slash after json should be removed. The parameters should be sorted for better cache-ability (at least those who cache by URL).
Hey MTM,
Geo::Coder::OpenCage currently points at http://prototype.opencagedata.com/geocode/v1/json/ but I think that should be changed?
https://github.com/lokku/perl-Geo-Coder-OpenCage/blob/master/lib/Geo/Coder/OpenCage.pm#L23
Ed said:
[09:25:33] Ed: if you don't mind pls do ASAP as at 13:00 I have call with the python guy
[09:25:42] Ed: and will tell him to basically copy the perl module
If you let me know what URL it should be I'll fix it and ship a 0.02 to CPAN.
Thanks,
Alex
Some of my smoker systems fail two test files like this:
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "IO::Socket::SSL 1.42...") at lib/Geo/Coder/OpenCage.pm line 86.
t/04-402-response.t .....
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "IO::Socket::SSL 1.42...") at lib/Geo/Coder/OpenCage.pm line 86.
t/05-403-response.t .....
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
After installing IO::Socket::SSL the test suite pass. So probably IO::Socket::SSL should be declared as a prerequisite. And maybe diagnostics should be better if this test fails.
Using the code in Synopsis of Geo::Coder::OpenCage with API key all works ok.
Using the code in Synopsis of Geo::Coder::Many::OpenCage with same API ( had to remove brackets from new as expects even list not hashref )
Can't locate object method "response" via package "Geo::Coder::OpenCage" ..perl/5.20.2/Geo/Coder/Many/OpenCage.pm line 95.
Modules installed from CPAN and running on debian/jessie.
Except in the case of some very serious bug in HTTP::Tiny or LWP::UserAgent, the get
method will always return a true result, so this if (!$response) { ... }
block will never, ever get run. Ever. At all.
That said, if it ever did run, you'd get further issues because you're accessing $response->{reason}
; you're assuming $response
is a hashref. But hashrefs are always true. Not false.
You can honestly just get rid of that entire if
block though because the condition will never be true.
Classes in the Geo::Coder::* namespace support the 'ua' method to get/set the useragent. See, for example, https://github.com/gitpan/Geo-Coder-Bing/blob/master/lib/Geo/Coder/Bing.pm
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.