| 1 | package WWW::YahooMaps; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | require 5.005_62; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '0.3'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub stringtolink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringtolink: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my ($country, $language, $string, $swap) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $string =~ m@^([^\;\n]+)[\;\n]+([^\;\n]+)@s; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($street, $city) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($swap) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ($street, $city) = ($city, $street); | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my %addr = ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | "street" => $street, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | "city" => $city, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | "country" => $country, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | "language" => "us", | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $url = hashreftolink(\%addr); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return $url; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub hashreftolink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hashreftolink: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ($rh_addr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $rh_addr->{language} = "us"; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | #test if the language we want exists, whether we have given at least a country and a city | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (&testlang($rh_addr->{language}) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
&testlang($rh_addr->{"language"}) and &testcountry($rh_addr->{"country"}) and &cleanstring($rh_addr->{"city"})
&testlang($rh_addr->{"language"}) and &testcountry($rh_addr->{"country"})
MC/DC0%0/3
&testlang($rh_addr->{"language"}) and &testcountry($rh_addr->{"country"}) and &cleanstring($rh_addr->{"city"})
&testlang($rh_addr->{"language"})
&testcountry($rh_addr->{"country"})
&cleanstring($rh_addr->{"city"})
Truth table0%0/4
A and B and C
A= &testlang($rh_addr->{"language"})B= &testcountry($rh_addr->{"country"})C= &cleanstring($rh_addr->{"city"})
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | &testcountry($rh_addr->{country}) && | ||||||||||||||||||||||||||||||||||||||||||
| 46 | &cleanstring($rh_addr->{city})) { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $rh_addr->{language} = &ukcheck($rh_addr->{language}); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $rh_addr->{country} = &ukcheck($rh_addr->{country}); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | #special treatment for canada and US | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($rh_addr->{country} eq "ca") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $rh_addr->{language} = "ca"; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ($rh_addr->{country} eq "us") { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $rh_addr->{language} = "us"; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | #take care of US dot-related issues | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $langdot = ''; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($rh_addr->{language} eq "us") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $rh_addr->{language} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $langdot = '.'; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $url = ""; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $url = "http://" . $rh_addr->{language} . $langdot . "maps.yahoo.com"; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $url .= "/py"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($rh_addr->{country} ne "ca") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $url .= "/lg:" . $rh_addr->{language}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $url .= "/lc:" . $rh_addr->{language}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $url .= "/maps_result?BFCat=&Pyt=Tmap&newFL="; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # street | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($rh_addr->{street}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $street = cleanstring($rh_addr->{street}); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $street = uri_escape($street); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $url .= "&addr=" . $street; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # city | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $city = cleanstring($rh_addr->{city}); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $city = uri_escape($city); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $url .= "&csz=" . $city; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # country | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $url .= "&country=" . $rh_addr->{country}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $url; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub ukcheck { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ukcheck: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | # needed because "uk" is not a ISO 3166 code | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # "gb" is the code, but Yahoo! uses uk | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my ($string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($string eq "gb"){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return "uk"; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub testlang { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
testlang: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my ($lang) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ($lang){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | # list of languages in which Yahoo offers maps | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my %langs = ( | |||||||||||||||||||||||||||||||||||||||||
| 121 | "us" => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $langs{$lang} ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub testcountry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
testcountry: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my ($cty) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($cty){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | # list of countries for which Yahoo has maps | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my %ctys = ( | |||||||||||||||||||||||||||||||||||||||||
| 135 | "ca" => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | "us" => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return $ctys{$cty} ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub cleanstring { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cleanstring: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | #remove unecessary whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my ($string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $string =~ s@\n@ @g; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $string =~ s@^\s+@@g; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $string =~ s@\s+$@@g; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||