line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Yahoo; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
3
|
|
|
3
|
|
26038
|
$Geo::Coder::Yahoo::VERSION = '0.50'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
29
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
93
|
|
7
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
98
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
18
|
use Carp qw(croak); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
207
|
|
10
|
3
|
|
|
3
|
|
959
|
use Encode qw(decode); |
|
3
|
|
|
|
|
11904
|
|
|
3
|
|
|
|
|
250
|
|
11
|
3
|
|
|
3
|
|
1020
|
use URI 1.36; |
|
3
|
|
|
|
|
13486
|
|
|
3
|
|
|
|
|
70
|
|
12
|
3
|
|
|
3
|
|
2518
|
use URI::QueryParam; |
|
3
|
|
|
|
|
2142
|
|
|
3
|
|
|
|
|
81
|
|
13
|
3
|
|
|
3
|
|
962
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
43764
|
|
|
3
|
|
|
|
|
109
|
|
14
|
3
|
|
|
3
|
|
1273
|
use Yahoo::Search::XML 20100612; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub ua { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
$self->{ua} = shift if @_; |
19
|
|
|
|
|
|
|
return $self->{ua}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
my $class = shift; |
24
|
|
|
|
|
|
|
my %args = @_; |
25
|
|
|
|
|
|
|
return bless { |
26
|
|
|
|
|
|
|
appid => $args{appid}, |
27
|
|
|
|
|
|
|
on_error => $args{on_error} || sub { undef }, |
28
|
|
|
|
|
|
|
ua => $args{ua} || do { |
29
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
30
|
|
|
|
|
|
|
$ua->agent(__PACKAGE__ . '/' . ($Geo::Coder::Yahoo::VERSION || 'git')); |
31
|
|
|
|
|
|
|
$ua->env_proxy; |
32
|
|
|
|
|
|
|
$ua; |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
}, $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub geocode { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
my %args = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $appid = $args{appid}; |
42
|
|
|
|
|
|
|
$appid = $self->{appid} if !$appid and ref $self; |
43
|
|
|
|
|
|
|
croak "appid parameter required" unless $appid; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $u = URI->new('http://api.local.yahoo.com/MapsService/V1/geocode'); |
46
|
|
|
|
|
|
|
$u->query_param(appid => $self->{appid}); |
47
|
|
|
|
|
|
|
$u->query_param($_ => $args{$_}) for keys %args; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $resp = $self->ua->get($u->as_string); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return $self->{on_error}->($self, $resp) |
52
|
|
|
|
|
|
|
if not $resp->is_success; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $parsed = Yahoo::Search::XML::Parse($resp->content); |
55
|
|
|
|
|
|
|
return undef unless $parsed and $parsed->{Result}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $results = $parsed->{Result}; |
58
|
|
|
|
|
|
|
$results = [ $parsed->{Result} ] if ref $parsed->{Result} eq 'HASH'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
for my $d (@$results) { |
61
|
|
|
|
|
|
|
for my $k (keys %$d) { |
62
|
|
|
|
|
|
|
$d->{lc $k} = delete $d->{$k}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$results; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |