File Coverage

blib/lib/WebService/StreetMapLink/MapQuest.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 12 58.3
condition 4 8 50.0
subroutine 5 5 100.0
pod 2 2 100.0
total 47 56 83.9


line stmt bran cond sub pod time code
1             package WebService::StreetMapLink::MapQuest;
2              
3 4     4   26405 use strict;
  4         9  
  4         153  
4              
5 4     4   880 use Geography::States;
  4         4746  
  4         127  
6              
7 4     4   23 use base 'WebService::StreetMapLink';
  4         7  
  4         2410  
8             __PACKAGE__->RegisterSubclass();
9              
10              
11             my %Query = ( usa => { countryid => 'US',
12             country => 'US',
13             },
14             canada => { countryid => 41,
15             country => 'CA',
16             },
17             );
18              
19             my @Accents = ( [ qr/[\xE0-\xE2]/ => 'a' ],
20             [ qr/[\xE8-\xEA]/ => 'e' ],
21             [ qr/\xE7/ => 'c' ],
22             [ qr/\xF4/ => 'o' ],
23             );
24              
25 4     4 1 28 sub Countries { keys %Query }
26              
27             sub new
28             {
29 5     5 1 26 my $class = shift;
30 5         26 my %p = @_;
31              
32 5         9 local $_;
33             # remove accents from state names like Quebec or mapquest gets upset
34 5         18 for ( grep { defined } values %p )
  26         65  
35             {
36 26         96 foreach my $p (@Accents)
37             {
38 104         325 s/$p->[0]/$p->[1]/g;
39             }
40             }
41              
42 5 50       25 if ( defined $p{state} )
43             {
44 5 100       19 if ( length $p{state} > 2 )
45             {
46 2         18 $p{state} = Geography::States->new( $p{country} )->state( $p{state} );
47             }
48             }
49              
50             return
51 5 50 33     777 unless ( defined $p{address}
      33        
52             &&
53             ( ( defined $p{city} && defined $p{state} )
54             ||
55             defined $p{postal_code}
56             )
57             );
58              
59 5 50       23 return if $p{address} =~ /p\.?o\.\s+box/i;
60              
61 5         9 my %query = %{ $Query{ $p{country} } };
  5         32  
62              
63 5         17 foreach my $k ( qw( address city state ) )
64             {
65 15 50       70 $query{$k} = $p{$k}
66             if defined $p{$k};
67             }
68              
69 5 50       30 $query{zip} = $p{postal_code}
70             if defined $p{postal_code};
71              
72 5   100     32 $query{zoom} = $p{zoom} || 8;
73              
74 5         61 return bless { host => 'www.mapquest.com',
75             path => '/maps/map.adp',
76             query => \%query,
77             }, $class;
78             }
79              
80              
81             1;
82              
83             __END__