line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Ovi; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69800
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
86
|
|
4
|
2
|
|
|
2
|
|
85
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
147
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
162
|
|
7
|
2
|
|
|
2
|
|
3083
|
use Encode (); |
|
2
|
|
|
|
|
38795
|
|
|
2
|
|
|
|
|
55
|
|
8
|
2
|
|
|
2
|
|
3110
|
use JSON; |
|
2
|
|
|
|
|
98871
|
|
|
2
|
|
|
|
|
104
|
|
9
|
2
|
|
|
2
|
|
3693
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
220292
|
|
|
2
|
|
|
|
|
86
|
|
10
|
2
|
|
|
2
|
|
25
|
use URI; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1447
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
1139
|
my ($class, %params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# These will be required at some point in the future. |
19
|
|
|
|
|
|
|
# croak qq('appid' and 'token' are required); |
20
|
|
|
|
|
|
|
# unless ($params{appid} and $params{token}) { |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
7
|
my $self = bless \ %params, $class; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
33
|
|
|
48
|
$self->ua( |
25
|
|
|
|
|
|
|
$params{ua} || LWP::UserAgent->new(agent => "$class/$VERSION") |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
2
|
100
|
|
|
|
8
|
if ($self->{debug}) { |
29
|
1
|
|
|
0
|
|
6
|
my $dump_sub = sub { $_[0]->dump(maxlength => 0); return }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
30
|
1
|
|
|
|
|
3
|
$self->ua->set_my_handler(request_send => $dump_sub); |
31
|
1
|
|
|
|
|
695
|
$self->ua->set_my_handler(response_done => $dump_sub); |
32
|
1
|
|
50
|
|
|
47
|
$self->{compress} ||= 0; |
33
|
|
|
|
|
|
|
} |
34
|
2
|
100
|
|
|
|
12
|
if (exists $self->{compress} ? $self->{compress} : 1) { |
|
|
100
|
|
|
|
|
|
35
|
1
|
|
|
|
|
4
|
$self->ua->default_header(accept_encoding => 'gzip,deflate'); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
61
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
1
|
0
|
sub response { $_[0]->{response} } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub ua { |
44
|
5
|
|
|
5
|
1
|
4879
|
my ($self, $ua) = @_; |
45
|
5
|
100
|
|
|
|
14
|
if ($ua) { |
46
|
2
|
50
|
33
|
|
|
29
|
croak q('ua' must be (or derived from) an LWP::UserAgent') |
47
|
|
|
|
|
|
|
unless ref $ua and $ua->isa(q(LWP::UserAgent)); |
48
|
2
|
|
|
|
|
8
|
$self->{ua} = $ua; |
49
|
|
|
|
|
|
|
} |
50
|
5
|
|
|
|
|
17
|
return $self->{ua}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub geocode { |
54
|
0
|
|
|
0
|
1
|
|
my ($self, @params) = @_; |
55
|
0
|
0
|
|
|
|
|
my %params = (@params % 2) ? (location => @params) : @params; |
56
|
0
|
|
|
|
|
|
my $raw = delete $params{raw}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$_ = Encode::encode('utf-8', $_) for values %params; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
my $location = delete $params{location} or return; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if (my $language = delete $params{language}) { |
63
|
0
|
|
|
|
|
|
$params{la} = $language; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $uri = URI->new('http://where.desktop.mos.svc.ovi.com/NOSe/json'); |
67
|
0
|
|
|
|
|
|
$uri->query_form( |
68
|
|
|
|
|
|
|
app_id => $self->{appid}, |
69
|
|
|
|
|
|
|
token => $self->{token}, |
70
|
|
|
|
|
|
|
q => $location, |
71
|
|
|
|
|
|
|
vi => 'where', |
72
|
|
|
|
|
|
|
dv => 'oviMapsAPI', |
73
|
|
|
|
|
|
|
lat => 0, |
74
|
|
|
|
|
|
|
lon => 0, |
75
|
|
|
|
|
|
|
%params, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $res = $self->{response} = $self->ua->get($uri); |
79
|
0
|
0
|
|
|
|
|
return unless $res->is_success; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Change the content type of the response from 'application/json' so |
82
|
|
|
|
|
|
|
# HTTP::Message will decode the character encoding. |
83
|
0
|
|
|
|
|
|
$res->content_type('text/plain'); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $data = eval { from_json($res->decoded_content) }; |
|
0
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
return unless $data; |
87
|
0
|
0
|
|
|
|
|
return $data if $raw; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
my @results = @{ $data->{results} || [] }; |
|
0
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
return wantarray ? @results : $results[0]; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |