File Coverage

blib/lib/Interchange6/Schema/Populate/CountryLocale.pm
Criterion Covered Total %
statement 12 24 50.0
branch 0 2 0.0
condition n/a
subroutine 4 5 80.0
pod 1 1 100.0
total 17 32 53.1


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 3     3   11 use strict;
  3         5  
  3         98  
14 3     3   14 use warnings;
  3         4  
  3         87  
15              
16 3     3   500 use Moo;
  3         3031  
  3         18  
17 3     3   3319 use Locale::SubCountry;
  3         462211  
  3         1062  
18              
19             =head1 METHODS
20              
21             =head2 records
22              
23             Returns array reference containing one hash reference per country,
24             ready to use with populate schema method.
25              
26             =cut
27              
28             sub records {
29 0     0 1   my ( $has_state, $countries );
30 0           my @countries_with_states = qw(US CA); # United States, Canada
31 0           my @countries;
32 0           my $world = Locale::SubCountry::World->new;;
33 0           my %all_country_keyed_by_code = $world->code_full_name_hash;
34              
35             # populate countries hash
36 0           foreach my $country_code ( sort keys %all_country_keyed_by_code ){
37             #need regex to clean up records containing 'See (*)'
38 0           my $country_name = $all_country_keyed_by_code{$country_code};
39 0 0         if ( grep( /^$country_code$/, @countries_with_states ) ) {
40 0           $has_state = '1';
41             } else {
42 0           $has_state = '0';
43             }
44 0           push @countries, {'country_iso_code' => $country_code, 'name' => $country_name, 'show_states' => $has_state};
45             }
46              
47 0           return \@countries;
48             }
49              
50             1;