Schema/Populate/StateLocale.pm

filter: Statementstmt 100% 18 / 18 Branchbran 100% 5 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 100% 32 / 33 CC 6 SCAR 15.6
CC
6
Cov
100%
populate_states
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
« Schema/Result/Message.pm ↑ Summary Schema/ResultSet/Session.pm »
1 package Interchange6::Schema::Populate::StateLocale;
2  
3 =head1 NAME
4  
5 Interchange6::Schema::Populate::StateLocale
6  
7 =head1 DESCRIPTION
8  
9 This role provides population capabilities for the State class
10  
11 =cut
12  
13 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Locale::SubCountry;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 METHODS
17  
18 =head2 populate_states
19  
20 Returns array reference containing one hash reference per state,
21 ready to use with populate schema method.
22  
23 =cut
24  
25 sub populate_states {
26 3 ▶ my $self = shift;
Subroutine populate_states: called CC=6 SCAR=17.9
Pod documented
27  
28 3 my $countries =
29 $self->schema->resultset('Country')->search( { -bool => 'show_states' } );
30  
31 3 ▶ while ( my $country_result = $countries->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $country_result = $countries->next) 6 3 9
32  
33 6 my $country =
34 Locale::SubCountry->new( $country_result->country_iso_code );
35  
36 # should never happen so let Devel::Cover watch it for us
37 # uncoverable branch true
38 6 ▶ next unless $country->has_sub_countries;
Branch: 1 branch
BranchTrueFalseTotal
unless $country->has_sub_countries 0 6 6
39  
40 6 my %country_states_keyed_by_code = $country->code_full_name_hash;
41  
42 6 foreach my $state_code ( sort keys %country_states_keyed_by_code ) {
43  
44 # some US 'states' are not actually states of the US
45 next
46 210 ▶ if ( $country_result->country_iso_code eq 'US'
Branch: 1 branch
BranchTrueFalseTotal
if $country_result->country_iso_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/ 18 192 210
Condition100%3/3
$country_result->country_iso_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/
!ll&&!rl&&r
3915318
MC/DC100%2/2
$country_result->country_iso_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/
$country_result->country_iso_code eq "US" $state_code =~ /(AS|GU|MP|PR|UM|VI)/
Truth table100%3/3
A and B
A= $country_result->country_iso_code eq "US"B= $state_code =~ /(AS|GU|MP|PR|UM|VI)/
ABresult
0X0
100
111
47 && $state_code =~ /(AS|GU|MP|PR|UM|VI)/ );
48  
49 192 my $state_name = $country_states_keyed_by_code{$state_code};
50  
51 # remove (Junk) from some records
52 192 $state_name =~ s/\s*\([^)]*\)//g;
53  
54 192 $country_result->create_related(
55 'states',
56 {
57 'name' => $state_name,
58 'state_iso_code' => $state_code,
59 }
60 );
61 }
62 }
63 }
64  
65 4 1;
« Schema/Result/Message.pm ↑ Summary Schema/ResultSet/Session.pm »