File Coverage

blib/lib/IBGE/Municipios.pm
Criterion Covered Total %
statement 15 15 100.0
branch 6 6 100.0
condition 7 9 77.7
subroutine 4 4 100.0
pod 1 1 100.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package IBGE::Municipios;
2 2     2   240987 use strict;
  2         6  
  2         117  
3 2     2   30 use warnings;
  2         5  
  2         841  
4              
5             our $VERSION = 0.02;
6              
7             my %code_for_data = _init();
8              
9             sub codigo {
10 5     5 1 145035 my ($city, $state) = @_;
11             return ( $city
12             && $state
13             && exists $code_for_data{$state}
14             && exists $code_for_data{$state}{$city}
15 5 100 66     69 ? $code_for_data{$state}{$city}
16             : undef
17             );
18             }
19              
20             sub _init {
21 2     2   6 my %codes = ();
22              
23 2         17 while (my $line = ) {
24 11238         35659 my ($state, $code, $city) = split /,/ => $line;
25 11238 100       26518 chomp $city if defined $city;
26 11238 100 66     50492 next unless $state && $code && $city;
      100        
27 11142         49153 $codes{$state}{$city} = $code;
28             }
29 2         82 return %codes;
30             }
31              
32             1;
33             __DATA__