line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::YahooJapan; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18651
|
use 5.008004; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
29
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
949
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
44396
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
8
|
use HTTP::Request; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
9
|
1
|
|
|
1
|
|
392
|
use Location::GeoTool; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
16
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
17
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# This allows declaration use Geo::Coder::YahooJapan ':all'; |
20
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
21
|
|
|
|
|
|
|
# will save memory. |
22
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
) ] ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw( |
29
|
|
|
|
|
|
|
lookup |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Preloaded methods go here. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $entry_point = 'http://api.map.yahoo.co.jp/MapsService/V1/search'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $ua = undef; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub lookup { |
41
|
|
|
|
|
|
|
my $address = shift; |
42
|
|
|
|
|
|
|
my $opts = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$address or return undef; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$ua or $ua = LWP::UserAgent->new(agent => __PACKAGE__ . "/$VERSION"); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $datum = $opts->{datum} || 'wgs84'; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
defined $opts->{num} or $opts->{num} = 10; |
51
|
|
|
|
|
|
|
defined $opts->{prop} or $opts->{prop} = 'widget'; |
52
|
|
|
|
|
|
|
$address =~ s/([\W])/ sprintf "%%%02X", ord($1) /ge; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $params = { |
55
|
|
|
|
|
|
|
prop => $opts->{prop}, |
56
|
|
|
|
|
|
|
b => 1, |
57
|
|
|
|
|
|
|
n => int $opts->{num}, |
58
|
|
|
|
|
|
|
ac => "", |
59
|
|
|
|
|
|
|
st => "", |
60
|
|
|
|
|
|
|
p => $address |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $q = join "&", ( map { "$_=" . $params->{$_} } (keys %$params) ); |
64
|
|
|
|
|
|
|
my $url = "$entry_point?$q"; |
65
|
|
|
|
|
|
|
my $response = $ua->get( $url ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$response or return undef; |
68
|
|
|
|
|
|
|
my $content = $response->content; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my @items = (); |
71
|
|
|
|
|
|
|
@_ = split m|- |, $content;
|
72
|
|
|
|
|
|
|
scalar @_ == 0 and return undef; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
while ( $content =~ m|- (.+?)
|sg ) { |
75
|
|
|
|
|
|
|
my $item_content = $1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $result = {}; |
78
|
|
|
|
|
|
|
while ( $item_content =~ m|<(\w+)>(.+?)\1>|g ) { |
79
|
|
|
|
|
|
|
$result->{$1} = $2; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
if ( $datum !~ /^tokyo$/i ) { |
82
|
|
|
|
|
|
|
my $tokyo = Location::GeoTool->create_coord( |
83
|
|
|
|
|
|
|
$result->{latitude}, $result->{longitude}, 'tokyo', 'degree'); |
84
|
|
|
|
|
|
|
my $wgs = $tokyo->datum_wgs84; |
85
|
|
|
|
|
|
|
$wgs->format_degree; |
86
|
|
|
|
|
|
|
$result->{latitude} = $wgs->lat; |
87
|
|
|
|
|
|
|
$result->{longitude} = $wgs->long; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
push @items, $result; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return { |
94
|
|
|
|
|
|
|
datum => $datum, |
95
|
|
|
|
|
|
|
latitude => $items[0]->{latitude}, |
96
|
|
|
|
|
|
|
longitude => $items[0]->{longitude}, |
97
|
|
|
|
|
|
|
hits => scalar @items, |
98
|
|
|
|
|
|
|
items => \@items |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
__END__ |