File Coverage

blib/lib/IBGE/Municipios.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition 8 9 88.8
subroutine 4 4 100.0
pod 1 1 100.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package IBGE::Municipios;
2 2     2   34699 use strict;
  2         4  
  2         78  
3 2     2   7 use warnings;
  2         4  
  2         373  
4              
5             our $VERSION = 0.01;
6              
7             my %code_for_data = _init();
8              
9             sub codigo {
10 5     5 1 14 my ($city, $state) = @_;
11              
12 5 100 100     57 return ( $city
13             && $state
14             && exists $code_for_data{$state}
15             && exists $code_for_data{$state}{$city}
16             ? $code_for_data{$state}{$city}
17             : undef
18             );
19             }
20              
21             sub _init {
22 2     2   5 my %codes = ();
23              
24 2         20 while (my $line = ) {
25 11234         19237 my ($state, $code, $city) = split /,/ => $line;
26 11234 100 66     47330 next unless $state && $code && $city;
      100        
27              
28 11130         34370 $codes{$state}{$city} = $code;
29             }
30 2         68 return %codes;
31             }
32              
33             1;
34             __DATA__