blib/lib/Geo/Coder/Yahoo.pm

filter: Statementstmt 85.4% 47 / 55 Branchbran 33.3% 4 / 12 Conditioncond 28.5% 4 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 66.9% 71 / 106 CC 15 SCAR 27.5
CC
15
Cov
68%
geocode
35.6
new
4.5
ua
2.0
CRAP 15.7
↑ Summary
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
BranchTrueFalseTotal
if @_ 0 2 2
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; }
l!l&&r!l&&!r
030
$args{'ua'} || do { my $ua = 'LWP::UserAgent'->new; $ua->agent('Geo::Coder::Yahoo/' . ($Geo::Coder::Yahoo::VERSION || 'git')); $ua->env_proxy; $ua }
l!l&&r!l&&!r
030
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; }
ABresult
1X1
011
000
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 }
ABresult
1X1
011
000
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'
l!l
30
MC/DC0%0/1
$Geo::Coder::Yahoo::VERSION || 'git'
$Geo::Coder::Yahoo::VERSION
Truth table50%1/2
A
A= $Geo::Coder::Yahoo::VERSION
Aresult
11
00
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
BranchTrueFalseTotal
if not $appid and ref $self 2 0 2
Condition33%1/3
not $appid and ref $self
!ll&&!rl&&r
002
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
ABresult
0X0
100
111
43 2 ▶ croak "appid parameter required" unless $appid;
Branch: 1 branch
BranchTrueFalseTotal
unless $appid 0 2 2
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
BranchTrueFalseTotal
unless $resp->is_success 2 0 2
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
BranchTrueFalseTotal
unless $parsed and $parsed->{"Result"} 0 0 0
Condition0%0/3
$parsed and $parsed->{"Result"}
!ll&&!rl&&r
000
MC/DC0%0/2
$parsed and $parsed->{"Result"}
$parsed $parsed->{"Result"}
Truth table0%0/3
A and B
A= $parsedB= $parsed->{"Result"}
ABresult
0X0
100
111
56  
57 0 my $results = $parsed->{Result};
58 0 ▶ $results = [ $parsed->{Result} ] if ref $parsed->{Result} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $parsed->{"Result"} eq "HASH" 0 0 0
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__
↑ Summary