line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
4
|
|
2253
|
use Moo::Role; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
64
|
|
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
|
|
|
3
|
1
|
124
|
my $self = shift; |
25
|
3
|
|
|
|
|
21
|
my $schema = $self->schema; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
16
|
my $countries = |
28
|
|
|
|
|
|
|
$schema->resultset('Country')->search( undef, { prefetch => 'states' } ); |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
2167
|
my $zones = $schema->resultset('Zone'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# one zone per country |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
1141
|
while ( my $country = $countries->next ) { |
35
|
|
|
|
|
|
|
|
36
|
747
|
|
|
|
|
1602707
|
$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
|
747
|
|
|
|
|
5207306
|
my $states = $country->states; |
47
|
|
|
|
|
|
|
|
48
|
747
|
|
|
|
|
248812
|
while ( my $state = $states->next ) { |
49
|
|
|
|
|
|
|
|
50
|
192
|
|
|
|
|
1837240
|
my $name = $country->name . " - " . $state->name; |
51
|
|
|
|
|
|
|
|
52
|
192
|
|
|
|
|
12420
|
$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
|
|
|
|
|
438
|
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
|
|
|
|
|
15874
|
zone_states => [ map { { 'states_id' => $_ } } @lower48states ], |
|
147
|
|
|
|
|
571
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# EU member states |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
360469
|
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
|
|
|
|
|
2013
|
[ map { { 'country_iso_code' => $_ } } @eu_countries ], |
|
84
|
|
|
|
|
211
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# EU VAT countries = EU + Isle of Man |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
205415
|
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
|
|
|
|
|
1243
|
[ map { { 'country_iso_code' => $_ } } @eu_vat_countries ], |
|
87
|
|
|
|
|
207
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |