| 1 | package Geo::Coder::Ovi; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 13 | 2 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 2 | 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 | my $self = bless \ %params, $class; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | $self->ua( | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | $params{ua} || LWP::UserAgent->new(agent => "$class/$VERSION") | ||||||||||||||||||||||||||
|
Condition33%1/3
$params{'ua'} || 'LWP::UserAgent'->new('agent', "$class/$Geo::Coder::Ovi::VERSION")
MC/DC0%0/2
$params{'ua'} || 'LWP::UserAgent'->new('agent', "$class/$Geo::Coder::Ovi::VERSION")
$params{'ua'}
'LWP::UserAgent'->new('agent', "$class/$Geo::Coder::Ovi::VERSION")
Truth table33%1/3
A || B
A= $params{'ua'}B= 'LWP::UserAgent'->new('agent', "$class/$Geo::Coder::Ovi::VERSION")
| |||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $dump_sub = sub { $_[0]->dump(maxlength => 0); return }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 30 | 1 | $self->ua->set_my_handler(request_send => $dump_sub); | |||||||||||||||||||||||||||
| 31 | 1 | $self->ua->set_my_handler(response_done => $dump_sub); | |||||||||||||||||||||||||||
| 32 | 1 | ▶ | $self->{compress} ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"compress"} ||= 0
MC/DC0%0/1
$self->{"compress"} ||= 0
$self->{"compress"}
Truth table50%1/2
A
A= $self->{"compress"}
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | if (exists $self->{compress} ? $self->{compress} : 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 35 | 1 | $self->ua->default_header(accept_encoding => 'gzip,deflate'); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | return $self; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub response { $_[0]->{response} } | ||||||||||||||||||||||||||
|
Subroutine
response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | ▶ | sub ua { | ||||||||||||||||||||||||||
|
Subroutine
ua: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 5 | my ($self, $ua) = @_; | |||||||||||||||||||||||||||
| 45 | 5 | ▶ | if ($ua) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | croak q('ua' must be (or derived from) an LWP::UserAgent') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $ua and $ua->isa("LWP::UserAgent")
MC/DC0%0/2
ref $ua and $ua->isa("LWP::UserAgent")
ref $ua
$ua->isa("LWP::UserAgent")
Truth table33%1/3
A and B
A= ref $uaB= $ua->isa("LWP::UserAgent")
| |||||||||||||||||||||||||||||
| 47 | unless ref $ua and $ua->isa(q(LWP::UserAgent)); | ||||||||||||||||||||||||||||
| 48 | 2 | $self->{ua} = $ua; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 5 | return $self->{ua}; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub geocode { | ||||||||||||||||||||||||||
|
Subroutine
geocode: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($self, @params) = @_; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | my %params = (@params % 2) ? (location => @params) : @params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | my $raw = delete $params{raw}; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $_ = Encode::encode('utf-8', $_) for values %params; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $location = delete $params{location} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (my $language = delete $params{language}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $params{la} = $language; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $uri = URI->new('http://where.desktop.mos.svc.ovi.com/NOSe/json'); | |||||||||||||||||||||||||||
| 67 | $uri->query_form( | ||||||||||||||||||||||||||||
| 68 | app_id => $self->{appid}, | ||||||||||||||||||||||||||||
| 69 | token => $self->{token}, | ||||||||||||||||||||||||||||
| 70 | 0 | 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 | ▶ | return unless $res->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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) }; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | return unless $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return $data if $raw; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my @results = @{ $data->{results} || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$data->{'results'} || []
MC/DC0%0/1
$data->{'results'} || []
$data->{'results'}
Truth table0%0/2
A
A= $data->{'results'}
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return wantarray ? @results : $results[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||