File Coverage

blib/lib/WebService/StreetMapLink/Google.pm
Criterion Covered Total %
statement 25 26 96.1
branch 3 6 50.0
condition 2 6 33.3
subroutine 6 7 85.7
pod 3 4 75.0
total 39 49 79.5


line stmt bran cond sub pod time code
1             package WebService::StreetMapLink::Google;
2              
3 4     4   23 use strict;
  4         8  
  4         139  
4              
5 4     4   2909 use Geography::States;
  4         15455  
  4         291  
6              
7 4     4   34 use base 'WebService::StreetMapLink';
  4         9  
  4         2233  
8             __PACKAGE__->RegisterSubclass(99);
9              
10              
11             my @Accents = ( [ qr/[\xE0-\xE2]/ => 'a' ],
12             [ qr/[\xE8-\xEA]/ => 'e' ],
13             [ qr/\xE7/ => 'c' ],
14             [ qr/\xF4/ => 'o' ],
15             );
16              
17             sub Countries
18             {
19 4     4 1 25 return ( qw( australia austria belgium
20             canada denmark
21             france germany hungary
22             italy netherlands
23             singapore spain
24             sweden switzerland
25             uk usa
26             ),
27             'czech republic',
28             'puerto rico'
29             );
30             }
31              
32 0     0 0 0 sub Priority { 99 }
33              
34             sub new
35             {
36 5     5 1 9 my $class = shift;
37 5         19 my %p = @_;
38              
39 5         7 local $_;
40             # remove accents from state names like Quebec or google gets upset
41 5         11 for ( grep { defined } values %p )
  24         45  
42             {
43 24         33 foreach my $p (@Accents)
44             {
45 96         311 s/$p->[0]/$p->[1]/g;
46             }
47             }
48              
49             return
50 5 50 33     48 unless ( defined $p{address}
      33        
51             &&
52             ( ( defined $p{city}
53             && ( defined $p{state} || $p{country} ne 'usa' )
54             )
55             ||
56             defined $p{postal_code}
57             )
58             );
59              
60 5 50       26 return if $p{address} =~ /p\.?o\.\s+box/i;
61              
62 5 50       20 $p{postal_code} =~ s/-\d{4}$//
63             if defined $p{postal_code};
64              
65 25         56 my $q =
66             ( join ',',
67 25         74 grep { defined }
68 5         11 map { $p{$_} } qw( address city state postal_code country )
69             );
70              
71 5         112 return bless { host => 'maps.google.com',
72             path => '/maps',
73             query => { q => $q }
74             }, $class;
75             }
76              
77 1     1 1 12 sub service_name { 'Google Maps' }
78              
79              
80             1;
81              
82             __END__