sub
populate_states {
my
$self
=
shift
;
my
$countries
=
$self
->schema->resultset(
'Country'
)->search( {
-bool
=>
'show_states'
} );
while
(
my
$country_result
=
$countries
->
next
) {
my
$country
=
Locale::SubCountry->new(
$country_result
->country_iso_code );
next
unless
$country
->has_sub_countries;
my
%country_states_keyed_by_code
=
$country
->code_full_name_hash;
foreach
my
$state_code
(
sort
keys
%country_states_keyed_by_code
) {
next
if
(
$country_result
->country_iso_code eq
'US'
&&
$state_code
=~ /(AS|GU|MP|PR|UM|VI)/ );
my
$state_name
=
$country_states_keyed_by_code
{
$state_code
};
$state_name
=~ s/\s*\([^)]*\)//g;
$country_result
->create_related(
'states'
,
{
'name'
=>
$state_name
,
'state_iso_code'
=>
$state_code
,
}
);
}
}
}
1;