line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::GeoPlanet; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23575
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
867
|
use LWP; |
|
1
|
|
|
|
|
56729
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
10
|
use URI; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
2005
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
8
|
|
|
|
|
|
|
our $QUERY_API_URL = 'http://where.yahooapis.com/v1/'; |
9
|
|
|
|
|
|
|
our @required_params = qw(api_key); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub places { |
12
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
13
|
0
|
|
|
|
|
|
my %p = @_; |
14
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
15
|
0
|
|
|
|
|
|
$url .= "places"; |
16
|
0
|
0
|
|
|
|
|
if(defined $p{type}) { |
17
|
0
|
|
|
|
|
|
$url .= '$and(.q(' . $p{place} . '),.type(' . $p{type} . '));?'; |
18
|
|
|
|
|
|
|
} else { |
19
|
0
|
|
|
|
|
|
$url .= '.q(\'' . $p{place} . '\')?'; |
20
|
|
|
|
|
|
|
} |
21
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
22
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
23
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
24
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
25
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
26
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
27
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
28
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub place { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
my %p = @_; |
34
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
35
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '?'; |
36
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
37
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
38
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
39
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
40
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
41
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub parent { |
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
46
|
0
|
|
|
|
|
|
my %p = @_; |
47
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
48
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '/parent?'; |
49
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
50
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
51
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
52
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
53
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
54
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
55
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
56
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub ancestors { |
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
my %p = @_; |
62
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
63
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '/ancestors?'; |
64
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
65
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
66
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
67
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
68
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
69
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub belongtos { |
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
0
|
|
|
|
|
|
my %p = @_; |
75
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
76
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '/belongtos?'; |
77
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
78
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
79
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
80
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
81
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
82
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
83
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
84
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub neighbors { |
88
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
89
|
0
|
|
|
|
|
|
my %p = @_; |
90
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
91
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '/neighbors?'; |
92
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
93
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
94
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
95
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
96
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
97
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
98
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
99
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub siblings { |
103
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
my %p = @_; |
105
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
106
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '/siblings?'; |
107
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
108
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
109
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
110
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
111
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
112
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
113
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
114
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub children { |
118
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
119
|
0
|
|
|
|
|
|
my %p = @_; |
120
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
121
|
0
|
|
|
|
|
|
$url .= 'place/' . $p{woeid} . '/children?'; |
122
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
123
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
124
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
125
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
126
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
127
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
128
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
129
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub placetypes { |
133
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
134
|
0
|
|
|
|
|
|
my %p = @_; |
135
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
136
|
0
|
0
|
|
|
|
|
if(defined $p{type}) { |
137
|
0
|
|
|
|
|
|
$url .= "placetypes.type(" . $p{type} . ")?"; |
138
|
|
|
|
|
|
|
} else { |
139
|
0
|
|
|
|
|
|
$url .= "placetypes?"; |
140
|
|
|
|
|
|
|
} |
141
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
142
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
143
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
144
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
145
|
0
|
0
|
|
|
|
|
$url .= 'start=' . $p{start} . '&' if defined $p{start}; |
146
|
0
|
0
|
|
|
|
|
$url .= 'count=' . $p{count} . '&' if defined $p{count}; |
147
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
148
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub placetype { |
152
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
153
|
0
|
|
|
|
|
|
my %p = @_; |
154
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
155
|
0
|
|
|
|
|
|
$url .= "placetype/" . $p{woeid} . '?'; |
156
|
0
|
0
|
|
|
|
|
$url .= 'lang=' . $p{lang} . '&' if defined $p{lang}; |
157
|
0
|
0
|
|
|
|
|
$url .= 'format=' . $p{format} . '&' if defined $p{format}; |
158
|
0
|
0
|
|
|
|
|
$url .= 'callback=' . $p{callback} . '&' if defined $p{callback}; |
159
|
0
|
0
|
|
|
|
|
$url .= 'select=' . $p{select} . '&' if defined $p{select}; |
160
|
0
|
|
|
|
|
|
$url .= 'appid=' . $self->{api_key}; |
161
|
0
|
|
|
|
|
|
return $self->_make_request($url, 'get'); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _make_request { |
165
|
0
|
|
|
0
|
|
|
my $self = shift; |
166
|
0
|
|
|
|
|
|
my $url = shift; |
167
|
0
|
|
|
|
|
|
my $method = shift; |
168
|
0
|
|
|
|
|
|
my $u = URI->new($url); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $response = $self->{browser}->$method($u, 'Accept' => "application/xml"); |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
|
die "$method on $url failed: " . $response->status_line |
173
|
|
|
|
|
|
|
unless ( $response->is_success ); |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
return $response->content; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _check { |
179
|
0
|
|
|
0
|
|
|
my $self = shift; |
180
|
0
|
|
|
|
|
|
foreach my $param ( @required_params ) { |
181
|
0
|
0
|
|
|
|
|
if ( not defined $self->{$param} ) { |
182
|
0
|
|
|
|
|
|
die "Missing required parameter '$param'"; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub new { |
188
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
189
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
190
|
0
|
|
|
|
|
|
my %params = @_; |
191
|
0
|
|
|
|
|
|
my $client = bless \%params, $class; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# Verify arguments |
194
|
0
|
|
|
|
|
|
$client->_check; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
$client->{browser} = LWP::UserAgent->new; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
return $client; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
__END__ |