| 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 4 | ▶ | use Locale::SubCountry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 14 | ▶ | my ( $has_state, $countries ); | ||||||||
|
Subroutine
records: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 30 | 14 | my @countries_with_states = qw(US CA); # United States, Canada | |||||||||
| 31 | 14 | my @countries; | |||||||||
| 32 | 14 | my $world = Locale::SubCountry::World->new;; | |||||||||
| 33 | 14 | my %all_country_keyed_by_code = $world->code_full_name_hash; | |||||||||
| 34 | |||||||||||
| 35 | # populate countries hash | ||||||||||
| 36 | 14 | foreach my $country_code ( sort keys %all_country_keyed_by_code ){ | |||||||||
| 37 | #need regex to clean up records containing 'See (*)' | ||||||||||
| 38 | 3500 | my $country_name = $all_country_keyed_by_code{$country_code}; | |||||||||
| 39 | 3500 | ▶ | if ( grep( /^$country_code$/, @countries_with_states ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 28 | $has_state = '1'; | |||||||||
| 41 | } else { | ||||||||||
| 42 | 3472 | $has_state = '0'; | |||||||||
| 43 | } | ||||||||||
| 44 | 3500 | push @countries, {'country_iso_code' => $country_code, 'name' => $country_name, 'show_states' => $has_state}; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 14 | return \@countries; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 4 | 1; | |||||||||