File Coverage

blib/lib/Interchange6/Schema/Populate/CountryLocale.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package Interchange6::Schema::Populate::CountryLocale;
2              
3             =head1 NAME
4              
5             Interchange6::Schema::Populate::CountryLocale
6              
7             =head1 DESCRIPTION
8              
9             This module provides population capabilities for the Country schema
10              
11             =cut
12              
13 4     4   12199 use Moo::Role;
  4         10  
  4         24  
14 4     4   4221 use Locale::SubCountry;
  4         354314  
  4         1826  
15 4     4   2082 use namespace::clean;
  4         40258  
  4         34  
16              
17             =head1 METHODS
18              
19             =head2 populate_countries
20              
21             =cut
22              
23             sub populate_countries {
24 3     3 1 149 my $self = shift;
25 3         12 my $has_state;
26 3         18 my @countries_with_states = qw(US CA); # United States, Canada
27 3         42 my $world = Locale::SubCountry::World->new;;
28 3         40 my %all_country_keyed_by_code = $world->code_full_name_hash;
29              
30 3         977 my $rset = $self->schema->resultset('Country');
31              
32 3         3153 foreach my $country_code ( sort keys %all_country_keyed_by_code ){
33             #need regex to clean up records containing 'See (*)'
34 747         1357527 my $country_name = $all_country_keyed_by_code{$country_code};
35 747 100       14297 if ( grep( /^$country_code$/, @countries_with_states ) ) {
36 6         22 $has_state = '1';
37             } else {
38 741         2062 $has_state = '0';
39             }
40 747         4301 $rset->create(
41             {
42             'country_iso_code' => $country_code,
43             'name' => $country_name,
44             'show_states' => $has_state
45             }
46             );
47             }
48             }
49              
50             1;