Permalink
Browse files

add debug and compress options

  • Loading branch information...
gray committed Jun 24, 2010
1 parent cc8e176 commit 45bb6fd580252683e655faae23a1daffa0f79d50
Showing with 28 additions and 7 deletions.
  1. +1 −1 README
  2. +16 −5 lib/Geo/Coder/Multimap.pm
  3. +11 −1 xt/live.t
View
2 README
@@ -25,7 +25,7 @@ This module requires these other modules and libraries:
COPYRIGHT AND LICENCE
-Copyright (C) 2010 by gray <gray@cpan.org>
+Copyright (C) 2009-2010 by gray <gray@cpan.org>
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
View
@@ -13,11 +13,12 @@ our $VERSION = '0.01';
$VERSION = eval $VERSION;
sub new {
- my ($class, %params) = @_;
+ my ($class, @params) = @_;
+ my %params = (@params % 2) ? (apikey => @params) : @params;
- my $key = $params{apikey} or croak q('apikey' is required);
+ croak q('apikey' is required) unless $params{apikey};
- my $self = bless { key => $key }, $class;
+ my $self = bless \ %params, $class;
if ($params{ua}) {
$self->ua($params{ua});
@@ -26,6 +27,16 @@ sub new {
$self->{ua} = LWP::UserAgent->new(agent => "$class/$VERSION");
}
+ if ($self->{debug}) {
+ my $dump_sub = sub { $_[0]->dump(maxlength => 0); return };
+ $self->ua->set_my_handler(request_send => $dump_sub);
+ $self->ua->set_my_handler(response_done => $dump_sub);
+ }
+
+ $self->{compress} = 1 unless exists $self->{compress};
+ $self->ua->default_header(accept_encoding => 'gzip,deflate')
+ if $self->{compress};
+
return $self;
}
@@ -49,7 +60,7 @@ sub geocode {
$location = Encode::encode('utf-8', $location);
my $uri = URI->new(
- 'http://developer.multimap.com/API/geocode/1.2/' . $self->{key}
+ 'http://developer.multimap.com/API/geocode/1.2/' . $self->{apikey}
);
$uri->query_form(
qs => $location,
@@ -190,7 +201,7 @@ L<http://search.cpan.org/dist/Geo-Coder-Multimap>
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2010 gray <gray at cpan.org>, all rights reserved.
+Copyright (C) 2009-2010 gray <gray at cpan.org>, all rights reserved.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
View
@@ -11,7 +11,17 @@ else {
plan tests => 8;
}
-my $geocoder = Geo::Coder::Multimap->new(apikey => $ENV{MULTIMAP_APIKEY});
+my $debug = $ENV{GEO_CODER_MULTIMAP_DEBUG};
+unless ($debug) {
+ diag "Set GEO_CODER_MULTIMAP_DEBUG to see request/response data";
+}
+
+
+my $geocoder = Geo::Coder::Multimap->new(
+ apikey => $ENV{MULTIMAP_APIKEY},
+ debug => $debug,
+ compress => 0,
+);
{
my $address = 'Hollywood & Highland, Los Angeles, CA, US';
my $location = $geocoder->geocode($address);

0 comments on commit 45bb6fd

Please sign in to comment.