Schema/Populate/Zone.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod 100% 1 / 1 totaltotal 100% 30 / 30 CC 3 SCAR 9.2
CC
3
Cov
100%
populate_zones
3.0
BEGIN
1.0
CRAP 2.5
« Schema/Result/Cart.pm ↑ Summary Schema/Populate/CountryLocale.pm »
1 package Interchange6::Schema::Populate::Zone;
2  
3 =head1 NAME
4  
5 Interchange6::Schema::Populate::Zone
6  
7 =head1 DESCRIPTION
8  
9 This module provides population capabilities for the Zone schema
10  
11 =cut
12  
13 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 METHODS
16  
17 =head2 populate_zones
18  
19 Returns array reference containing one hash reference per zone ready to use with populate schema method.
20  
21 =cut
22  
23 sub populate_zones {
24 3 ▶ my $self = shift;
Subroutine populate_zones: called CC=3 SCAR=11.0
Pod documented
25 3 my $schema = $self->schema;
26  
27 3 my $countries =
28 $schema->resultset('Country')->search( undef, { prefetch => 'states' } );
29  
30 3 my $zones = $schema->resultset('Zone');
31  
32 # one zone per country
33  
34 3 ▶ while ( my $country = $countries->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $country = $countries->next) 750 3 753
35  
36 750 $zones->create(
37 {
38 zone => $country->name,
39 zone_countries =>
40 [ { country_iso_code => $country->country_iso_code } ],
41 }
42 );
43  
44 # one zone per state
45  
46 750 my $states = $country->states;
47  
48 750 ▶ while ( my $state = $states->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $state = $states->next) 192 750 942
49  
50 192 my $name = $country->name . " - " . $state->name;
51  
52 192 $zones->create(
53 {
54 zone => $name,
55 zone_countries =>
56 [ { country_iso_code => $country->country_iso_code } ],
57 zone_states => [ { states_id => $state->id } ],
58 }
59 );
60 }
61 }
62  
63 # US lower 48 includes all 51 from US except for Alaska and Hawaii
64  
65 3 my @lower48states = $schema->resultset('State')->search(
66 {
67 'country_iso_code' => 'US',
68 'state_iso_code' => { -not_in => [qw/ AK HI /] }
69 },
70 )->get_column('states_id')->all;
71  
72 $zones->create(
73 {
74 zone => 'US lower 48',
75 zone_countries => [ { country_iso_code => 'US' } ],
76 3 zone_states => [ map { { 'states_id' => $_ } } @lower48states ],
77 }
78 );
79  
80 # EU member states
81  
82 3 my @eu_countries = (
83 qw ( BE BG CZ DK DE EE GR ES FR HR IE IT CY LV LT LU HU MT
84 NL AT PL PT RO SI SK FI SE GB )
85 );
86  
87 $zones->create(
88 {
89 zone => 'EU member states',
90 zone_countries =>
91 3 [ map { { 'country_iso_code' => $_ } } @eu_countries ],
92 }
93 );
94  
95 # EU VAT countries = EU + Isle of Man
96  
97 3 my @eu_vat_countries = (
98 qw ( BE BG CZ DK DE EE GR ES FR HR IE IT CY LV LT LU HU MT
99 NL AT PL PT RO SI SK FI SE GB IM )
100 );
101  
102 $zones->create(
103 {
104 zone => 'EU VAT countries',
105 zone_countries =>
106 3 [ map { { 'country_iso_code' => $_ } } @eu_vat_countries ],
107 }
108 );
109 }
110  
111 4 1;
« Schema/Result/Cart.pm ↑ Summary Schema/Populate/CountryLocale.pm »