Schema/Populate/StateLocale.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 98.2% 55 / 56 CC 8 SCAR 16.7
CC
8
Cov
98%
records
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.3
« Test/Role/MySQL.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 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
BranchTrueFalseTotal
if ($country_object->{"show_states"} == 1) 14 1736 1750
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
BranchTrueFalseTotal
unless $country->has_sub_countries 0 14 14
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
BranchTrueFalseTotal
if $country_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/ 42 448 490
Condition100%3/3
$country_code eq "US" and $state_code =~ /(AS|GU|MP|PR|UM|VI)/
!ll&&!rl&&r
9135742
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)/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->generate_states_id == 1) { } 192 256 448
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;
« Test/Role/MySQL.pm ↑ Summary Schema/ResultSet/Session.pm »