| 1 | package Geo::Coder::Yahoo; | ||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 5 | $Geo::Coder::Yahoo::VERSION = '0.50'; | |||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use URI 1.36; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use URI::QueryParam; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Yahoo::Search::XML 20100612; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub ua { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
ua: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | $self->{ua} = shift if @_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 19 | 2 | return $self->{ua}; | |||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 23 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 24 | 3 | my %args = @_; | |||||||||||||||||||||||||||||||||||||
| 25 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 26 | appid => $args{appid}, | ||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | on_error => $args{on_error} || sub { undef }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | ua => $args{ua} || do { | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$args{'on_error'} || sub {
undef;
}
$args{'ua'} || do {
my $ua = 'LWP::UserAgent'->new;
$ua->agent('Geo::Coder::Yahoo/' . ($Geo::Coder::Yahoo::VERSION || 'git'));
$ua->env_proxy;
$ua
}
MC/DC0%0/2
$args{'on_error'} || sub {
undef;
}
$args{'on_error'}
sub {
undef;
}
MC/DC0%0/2
$args{'ua'} || do {
my $ua = 'LWP::UserAgent'->new;
$ua->agent('Geo::Coder::Yahoo/' . ($Geo::Coder::Yahoo::VERSION || 'git'));
$ua->env_proxy;
$ua
}
$args{'ua'}
do {
my $ua = 'LWP::UserAgent'->new;
$ua->agent('Geo::Coder::Yahoo/' . ($Geo::Coder::Yahoo::VERSION || 'git'));
$ua->env_proxy;
$ua
}
Truth table33%1/3
A || B
A= $args{'on_error'}B= sub {
undef;
}
Truth table33%1/3
A || B
A= $args{'ua'}B= do {
my $ua = 'LWP::UserAgent'->new;
$ua->agent('Geo::Coder::Yahoo/' . ($Geo::Coder::Yahoo::VERSION || 'git'));
$ua->env_proxy;
$ua
}
| |||||||||||||||||||||||||||||||||||||||
| 29 | 3 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | $ua->agent(__PACKAGE__ . '/' . ($Geo::Coder::Yahoo::VERSION || 'git')); | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Geo::Coder::Yahoo::VERSION || 'git'
MC/DC0%0/1
$Geo::Coder::Yahoo::VERSION || 'git'
$Geo::Coder::Yahoo::VERSION
Truth table50%1/2
A
A= $Geo::Coder::Yahoo::VERSION
| |||||||||||||||||||||||||||||||||||||||
| 31 | 3 | $ua->env_proxy; | |||||||||||||||||||||||||||||||||||||
| 32 | 3 | $ua; | |||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||
| 34 | }, $class; | ||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | sub geocode { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
geocode: called CC=11 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 39 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 2 | my $appid = $args{appid}; | |||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | $appid = $self->{appid} if !$appid and ref $self; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $appid and ref $self
MC/DC0%0/2
not $appid and ref $self
not $appid
ref $self
Truth table33%1/3
not(A) and B
A= not $appidB= ref $self
| |||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | croak "appid parameter required" unless $appid; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 2 | my $u = URI->new('http://api.local.yahoo.com/MapsService/V1/geocode'); | |||||||||||||||||||||||||||||||||||||
| 46 | 2 | $u->query_param(appid => $self->{appid}); | |||||||||||||||||||||||||||||||||||||
| 47 | 2 | $u->query_param($_ => $args{$_}) for keys %args; | |||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 2 | my $resp = $self->ua->get($u->as_string); | |||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | return $self->{on_error}->($self, $resp) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 52 | if not $resp->is_success; | ||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $parsed = Yahoo::Search::XML::Parse($resp->content); | |||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return undef unless $parsed and $parsed->{Result}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$parsed and $parsed->{"Result"}
MC/DC0%0/2
$parsed and $parsed->{"Result"}
$parsed
$parsed->{"Result"}
Truth table0%0/3
A and B
A= $parsedB= $parsed->{"Result"}
| |||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $results = $parsed->{Result}; | |||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $results = [ $parsed->{Result} ] if ref $parsed->{Result} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | for my $d (@$results) { | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | for my $k (keys %$d) { | |||||||||||||||||||||||||||||||||||||
| 62 | 0 | $d->{lc $k} = delete $d->{$k}; | |||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $results; | |||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 5 | 1; | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||||||