| 1 | package Interchange6::Schema::Populate::StateLocale; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Interchange6::Schema::Populate::StateLocale | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | This module provides population capabilities for the State 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 Interchange6::Schema::Populate::CountryLocale; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use Locale::SubCountry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head2 generate_states_id | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Boolean specifiying whether the L</records> method should add states_id. Defaults to 0. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | has generate_states_id => ( | |||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | default => 0, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 states_id_initial_value | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | The initial value of the states_id sequence (only used if generate_states_id is 1). Default is 1. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | has states_id_initial_value => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | default => 1, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 METHODS | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 records | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Returns array reference containing one hash reference per state, | ||||||||||||||||||||||||||||
| 49 | ready to use with populate schema method. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub records { | ||||||||||||||||||||||||||||
| 54 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
records: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 7 | my $states_id = $self->states_id_initial_value; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 7 | my @states; | |||||||||||||||||||||||||||
| 58 | 7 | my $countries = Interchange6::Schema::Populate::CountryLocale->new->records; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 7 | for my $country_object (@$countries) { | |||||||||||||||||||||||||||
| 61 | 1750 | ▶ | if ( $country_object->{'show_states'} == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 14 | my $country_code = $country_object->{'country_iso_code'}; | |||||||||||||||||||||||||||
| 63 | 14 | my $country = Locale::SubCountry->new( $country_object->{'country_iso_code'} ); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 14 | ▶ | next unless $country->has_sub_countries; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 14 | my %country_states_keyed_by_code = $country->code_full_name_hash; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 14 | foreach my $state_code ( sort keys %country_states_keyed_by_code ) { | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # some US 'states' are not actually states of the US | ||||||||||||||||||||||||||||
| 72 | next | ||||||||||||||||||||||||||||
| 73 | 490 | ▶ | if ( $country_code eq 'US' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$country_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/
MC/DC100%2/2
$country_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/
$country_code eq "US"
$state_code =~ /(AS|GU|MP|PR|UM|VI)/
Truth table100%3/3
A and B
A= $country_code eq "US"B= $state_code =~ /(AS|GU|MP|PR|UM|VI)/
| |||||||||||||||||||||||||||||
| 74 | && $state_code =~ /(AS|GU|MP|PR|UM|VI)/ ); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 448 | my $state_name = $country_states_keyed_by_code{$state_code}; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # remove (Junk) from some records | ||||||||||||||||||||||||||||
| 79 | 448 | $state_name =~ s/\s*\([^)]*\)//g; | |||||||||||||||||||||||||||
| 80 | 448 | ▶ | if ( $self->generate_states_id == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 192 | push @states, | |||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 'states_id' => $states_id++, | ||||||||||||||||||||||||||||
| 84 | 'name' => $state_name, | ||||||||||||||||||||||||||||
| 85 | 'state_iso_code' => $state_code, | ||||||||||||||||||||||||||||
| 86 | 'country_iso_code' => $country_code | ||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 256 | push @states, | |||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 'name' => $state_name, | ||||||||||||||||||||||||||||
| 93 | 'state_iso_code' => $state_code, | ||||||||||||||||||||||||||||
| 94 | 'country_iso_code' => $country_code | ||||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 7 | return \@states; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 4 | 1; | |||||||||||||||||||||||||||