line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::Country::EU; |
2
|
|
|
|
|
|
|
$Locale::Country::EU::VERSION = '0.004'; |
3
|
1
|
|
|
1
|
|
101787
|
use 5.016003; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
18
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
102
|
|
8
|
1
|
|
|
1
|
|
627
|
use Data::Util qw( is_hash_ref is_array_ref); |
|
1
|
|
|
|
|
1089
|
|
|
1
|
|
|
|
|
1646
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
15
|
|
|
|
|
|
|
is_eu_country |
16
|
|
|
|
|
|
|
list_eu_countries |
17
|
|
|
|
|
|
|
$ISO_CODES |
18
|
|
|
|
|
|
|
$EU_COUNTRY_MAP |
19
|
|
|
|
|
|
|
) ] ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ABSTRACT: Module to check if a country is in the European Union ( EU ) using various ISO data formats |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $EU_COUNTRY_MAP = [ |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
'ISO-name' => 'Bulgaria', |
29
|
|
|
|
|
|
|
'ISO-m49' => '100', |
30
|
|
|
|
|
|
|
'ISO-alpha3' => 'BGR', |
31
|
|
|
|
|
|
|
'ISO-alpha2' => 'BG', |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
'ISO-name' => 'Hungary', |
35
|
|
|
|
|
|
|
'ISO-m49' => '348', |
36
|
|
|
|
|
|
|
'ISO-alpha3' => 'HUN', |
37
|
|
|
|
|
|
|
'ISO-alpha2' => 'HU', |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
'ISO-name' => 'Poland', |
41
|
|
|
|
|
|
|
'ISO-m49' => '616', |
42
|
|
|
|
|
|
|
'ISO-alpha3' => 'POL', |
43
|
|
|
|
|
|
|
'ISO-alpha2' => 'PL', |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
'ISO-name' => 'Romania', |
47
|
|
|
|
|
|
|
'ISO-m49' => '642', |
48
|
|
|
|
|
|
|
'ISO-alpha3' => 'ROU', |
49
|
|
|
|
|
|
|
'ISO-alpha2' => 'RO', |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
'ISO-name' => 'Slovakia', |
53
|
|
|
|
|
|
|
'ISO-m49' => '703', |
54
|
|
|
|
|
|
|
'ISO-alpha3' => 'SVK', |
55
|
|
|
|
|
|
|
'ISO-alpha2' => 'SK', |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
'ISO-name' => 'Denmark', |
59
|
|
|
|
|
|
|
'ISO-m49' => '208', |
60
|
|
|
|
|
|
|
'ISO-alpha3' => 'DNK', |
61
|
|
|
|
|
|
|
'ISO-alpha2' => 'DK', |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
'ISO-name' => 'Estonia', |
65
|
|
|
|
|
|
|
'ISO-m49' => '233', |
66
|
|
|
|
|
|
|
'ISO-alpha3' => 'EST', |
67
|
|
|
|
|
|
|
'ISO-alpha2' => 'EE', |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
'ISO-name' => 'Finland', |
71
|
|
|
|
|
|
|
'ISO-m49' => '246', |
72
|
|
|
|
|
|
|
'ISO-alpha3' => 'FIN', |
73
|
|
|
|
|
|
|
'ISO-alpha2' => 'FI', |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
'ISO-name' => 'Iceland', |
77
|
|
|
|
|
|
|
'ISO-m49' => '352', |
78
|
|
|
|
|
|
|
'ISO-alpha3' => 'ISL', |
79
|
|
|
|
|
|
|
'ISO-alpha2' => 'IS', |
80
|
|
|
|
|
|
|
'EFTA-member' => 'true', |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
'ISO-name' => 'Ireland', |
84
|
|
|
|
|
|
|
'ISO-m49' => '372', |
85
|
|
|
|
|
|
|
'ISO-alpha3' => 'IRL', |
86
|
|
|
|
|
|
|
'ISO-alpha2' => 'IE', |
87
|
|
|
|
|
|
|
}, |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
'ISO-name' => 'Lithuania', |
90
|
|
|
|
|
|
|
'ISO-m49' => '440', |
91
|
|
|
|
|
|
|
'ISO-alpha3' => 'LTU', |
92
|
|
|
|
|
|
|
'ISO-alpha2' => 'LT', |
93
|
|
|
|
|
|
|
}, |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
'ISO-name' => 'Norway', |
96
|
|
|
|
|
|
|
'ISO-m49' => '578', |
97
|
|
|
|
|
|
|
'ISO-alpha3' => 'NOR', |
98
|
|
|
|
|
|
|
'ISO-alpha2' => 'NO', |
99
|
|
|
|
|
|
|
'EFTA-member' => 'true', |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
'ISO-name' => 'Sweden', |
103
|
|
|
|
|
|
|
'ISO-m49' => '752', |
104
|
|
|
|
|
|
|
'ISO-alpha3' => 'SWE', |
105
|
|
|
|
|
|
|
'ISO-alpha2' => 'SE', |
106
|
|
|
|
|
|
|
}, |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
'ISO-name' => 'United Kingdom', |
109
|
|
|
|
|
|
|
'ISO-m49' => '826', |
110
|
|
|
|
|
|
|
'ISO-alpha3' => 'GBR', |
111
|
|
|
|
|
|
|
'ISO-alpha2' => 'GB', |
112
|
|
|
|
|
|
|
}, |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
'ISO-name' => 'Croatia', |
115
|
|
|
|
|
|
|
'ISO-m49' => '191', |
116
|
|
|
|
|
|
|
'ISO-alpha3' => 'HRV', |
117
|
|
|
|
|
|
|
'ISO-alpha2' => 'HR', |
118
|
|
|
|
|
|
|
}, |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
'ISO-name' => 'Greece', |
121
|
|
|
|
|
|
|
'ISO-m49' => '300', |
122
|
|
|
|
|
|
|
'ISO-alpha3' => 'GRC', |
123
|
|
|
|
|
|
|
'ISO-alpha2' => 'GR', |
124
|
|
|
|
|
|
|
}, |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
'ISO-name' => 'Italy', |
127
|
|
|
|
|
|
|
'ISO-m49' => '380', |
128
|
|
|
|
|
|
|
'ISO-alpha3' => 'ITA', |
129
|
|
|
|
|
|
|
'ISO-alpha2' => 'IT', |
130
|
|
|
|
|
|
|
}, |
131
|
|
|
|
|
|
|
{ |
132
|
|
|
|
|
|
|
'ISO-name' => 'Malta', |
133
|
|
|
|
|
|
|
'ISO-m49' => '470', |
134
|
|
|
|
|
|
|
'ISO-alpha3' => 'MLT', |
135
|
|
|
|
|
|
|
'ISO-alpha2' => 'MT', |
136
|
|
|
|
|
|
|
}, |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
'ISO-name' => 'Portugal', |
139
|
|
|
|
|
|
|
'ISO-m49' => '620', |
140
|
|
|
|
|
|
|
'ISO-alpha3' => 'PRT', |
141
|
|
|
|
|
|
|
'ISO-alpha2' => 'PT', |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
}, |
144
|
|
|
|
|
|
|
{ |
145
|
|
|
|
|
|
|
'ISO-name' => 'Slovenia', |
146
|
|
|
|
|
|
|
'ISO-m49' => '705', |
147
|
|
|
|
|
|
|
'ISO-alpha3' => 'SVN', |
148
|
|
|
|
|
|
|
'ISO-alpha2' => 'SI', |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
{ |
151
|
|
|
|
|
|
|
'ISO-name' => 'Spain', |
152
|
|
|
|
|
|
|
'ISO-m49' => '724', |
153
|
|
|
|
|
|
|
'ISO-alpha3' => 'ESP', |
154
|
|
|
|
|
|
|
'ISO-alpha2' => 'ES', |
155
|
|
|
|
|
|
|
}, |
156
|
|
|
|
|
|
|
{ |
157
|
|
|
|
|
|
|
'ISO-name' => 'Austria', |
158
|
|
|
|
|
|
|
'ISO-m49' => '40', |
159
|
|
|
|
|
|
|
'ISO-alpha3' => 'AUT', |
160
|
|
|
|
|
|
|
'ISO-alpha2' => 'AT', |
161
|
|
|
|
|
|
|
}, |
162
|
|
|
|
|
|
|
{ |
163
|
|
|
|
|
|
|
'ISO-name' => 'Belgium', |
164
|
|
|
|
|
|
|
'ISO-m49' => '56', |
165
|
|
|
|
|
|
|
'ISO-alpha3' => 'BEL', |
166
|
|
|
|
|
|
|
'ISO-alpha2' => 'BE', |
167
|
|
|
|
|
|
|
}, |
168
|
|
|
|
|
|
|
{ |
169
|
|
|
|
|
|
|
'ISO-name' => 'France', |
170
|
|
|
|
|
|
|
'ISO-m49' => '250', |
171
|
|
|
|
|
|
|
'ISO-alpha3' => 'FRA', |
172
|
|
|
|
|
|
|
'ISO-alpha2' => 'FR', |
173
|
|
|
|
|
|
|
}, |
174
|
|
|
|
|
|
|
{ |
175
|
|
|
|
|
|
|
'ISO-name' => 'Germany', |
176
|
|
|
|
|
|
|
'ISO-m49' => '276', |
177
|
|
|
|
|
|
|
'ISO-alpha3' => 'DEU', |
178
|
|
|
|
|
|
|
'ISO-alpha2' => 'DE', |
179
|
|
|
|
|
|
|
}, |
180
|
|
|
|
|
|
|
{ |
181
|
|
|
|
|
|
|
'ISO-name' => 'Liechtenstein', |
182
|
|
|
|
|
|
|
'ISO-m49' => '438', |
183
|
|
|
|
|
|
|
'ISO-alpha3' => 'LIE', |
184
|
|
|
|
|
|
|
'ISO-alpha2' => 'LI', |
185
|
|
|
|
|
|
|
'EFTA-member' => 'true', |
186
|
|
|
|
|
|
|
}, |
187
|
|
|
|
|
|
|
{ |
188
|
|
|
|
|
|
|
'ISO-name' => 'Luxembourg', |
189
|
|
|
|
|
|
|
'ISO-m49' => '442', |
190
|
|
|
|
|
|
|
'ISO-alpha3' => 'LUX', |
191
|
|
|
|
|
|
|
'ISO-alpha2' => 'LU', |
192
|
|
|
|
|
|
|
}, |
193
|
|
|
|
|
|
|
{ |
194
|
|
|
|
|
|
|
'ISO-name' => 'Netherlands', |
195
|
|
|
|
|
|
|
'ISO-m49' => '528', |
196
|
|
|
|
|
|
|
'ISO-alpha3' => 'NLD', |
197
|
|
|
|
|
|
|
'ISO-alpha2' => 'NL', |
198
|
|
|
|
|
|
|
}, |
199
|
|
|
|
|
|
|
{ |
200
|
|
|
|
|
|
|
'ISO-name' => 'Switzerland', |
201
|
|
|
|
|
|
|
'ISO-m49' => '756', |
202
|
|
|
|
|
|
|
'ISO-alpha3' => 'CHE', |
203
|
|
|
|
|
|
|
'ISO-alpha2' => 'CH', |
204
|
|
|
|
|
|
|
'EFTA-member' => 'true', |
205
|
|
|
|
|
|
|
}, |
206
|
|
|
|
|
|
|
{ |
207
|
|
|
|
|
|
|
'ISO-name' => 'Cyprus', |
208
|
|
|
|
|
|
|
'ISO-m49' => '196', |
209
|
|
|
|
|
|
|
'ISO-alpha3' => 'CYP', |
210
|
|
|
|
|
|
|
'ISO-alpha2' => 'CY', |
211
|
|
|
|
|
|
|
}, |
212
|
|
|
|
|
|
|
{ |
213
|
|
|
|
|
|
|
'ISO-name' => 'Czech Republic', |
214
|
|
|
|
|
|
|
'ISO-m49' => '203', |
215
|
|
|
|
|
|
|
'ISO-alpha3' => 'CZE', |
216
|
|
|
|
|
|
|
'ISO-alpha2' => 'CZ', |
217
|
|
|
|
|
|
|
}, |
218
|
|
|
|
|
|
|
{ |
219
|
|
|
|
|
|
|
'ISO-name' => 'Latvia', |
220
|
|
|
|
|
|
|
'ISO-m49' => '428', |
221
|
|
|
|
|
|
|
'ISO-alpha3' => 'LVA', |
222
|
|
|
|
|
|
|
'ISO-alpha2' => 'LV', |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
]; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
our $ISO_CODES = [ 'ISO-name', 'ISO-m49', 'ISO-alpha3', 'ISO-alpha2', 'EFTA-member' ]; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub is_eu_country { |
229
|
0
|
0
|
0
|
0
|
1
|
|
my %args = @_ == 1 && is_hash_ref( $_[0] ) ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
croak "Agrument country is required" |
232
|
0
|
0
|
|
|
|
|
unless ($args{country}); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
croak "Agrument exclude must be an ARRAY" |
235
|
0
|
0
|
0
|
|
|
|
if ($args{exclude} && !is_array_ref($args{exclude}) ); |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
0
|
|
|
|
my $include_EFTA = $args{include_efta} // 0; |
238
|
0
|
|
0
|
|
|
|
my $exclude_arr = $args{exclude} // []; |
239
|
0
|
|
|
|
|
|
my $check_country = $args{country}; |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
foreach my $country ( @{$EU_COUNTRY_MAP} ) |
|
0
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
{ |
243
|
0
|
0
|
|
|
|
|
if ( ! $include_EFTA ) { |
244
|
0
|
0
|
|
|
|
|
if ( $country->{'EFTA-member'} ) { |
245
|
0
|
|
|
|
|
|
next; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
|
my @country_values = values %{ $country }; |
|
0
|
|
|
|
|
|
|
250
|
0
|
0
|
|
|
|
|
if ( length $exclude_arr > 0 ) { |
251
|
0
|
|
|
|
|
|
my $should_exclude; |
252
|
0
|
|
|
|
|
|
foreach my $elt ( @{$exclude_arr} ) { |
|
0
|
|
|
|
|
|
|
253
|
0
|
0
|
|
|
|
|
if ( grep { /$elt/ } @country_values ) { |
|
0
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
$should_exclude = 1; |
255
|
0
|
|
|
|
|
|
last; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
0
|
0
|
|
|
|
|
if ( $should_exclude ) { |
260
|
0
|
|
|
|
|
|
next; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
foreach my $value ( @country_values ) |
265
|
|
|
|
|
|
|
{ |
266
|
0
|
0
|
|
|
|
|
if ( ref($value) eq 'ARRAY' ) { |
267
|
0
|
0
|
|
|
|
|
if ( grep { /^$check_country$/ } @{$value} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
268
|
0
|
|
|
|
|
|
return 1; |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
if ( $value eq $check_country ) { |
273
|
0
|
|
|
|
|
|
return 1; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
0
|
|
|
|
|
|
return 0; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub list_eu_countries { |
282
|
0
|
0
|
0
|
0
|
1
|
|
my %args = @_ == 1 && is_hash_ref( $_[0] ) ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
croak "Agrument exclude must be an ARRAY" |
285
|
0
|
0
|
0
|
|
|
|
if ($args{exclude} && ! is_array_ref($args{exclude}) ); |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
0
|
|
|
|
my $include_EFTA = $args{include_efta} // 0; |
288
|
0
|
|
0
|
|
|
|
my $exclude_arr = $args{exclude} // [ ]; |
289
|
0
|
|
|
|
|
|
my $data_key = $args{iso_code}; |
290
|
|
|
|
|
|
|
|
291
|
0
|
0
|
0
|
|
|
|
if ( $data_key && ! grep { $data_key eq $_ } @{$ISO_CODES} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
croak "Argument iso_code must be one of 'ISO-name', 'ISO-m49', 'ISO-alpha3', 'ISO-alpha2'"; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
|
296
|
0
|
|
|
|
|
|
my @return_countries; |
297
|
|
|
|
|
|
|
|
298
|
0
|
|
|
|
|
|
foreach my $country ( @{$EU_COUNTRY_MAP} ) |
|
0
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
{ |
300
|
0
|
0
|
|
|
|
|
if ( ! $include_EFTA ) { |
301
|
0
|
0
|
|
|
|
|
if ( $country->{'EFTA-member'} ) { |
302
|
0
|
|
|
|
|
|
next; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
|
my @country_values = values %{ $country }; |
|
0
|
|
|
|
|
|
|
307
|
0
|
0
|
|
|
|
|
if ( length $exclude_arr > 0 ) { |
308
|
0
|
|
|
|
|
|
my $should_exclude; |
309
|
0
|
|
|
|
|
|
foreach my $elt ( @{$exclude_arr} ) { |
|
0
|
|
|
|
|
|
|
310
|
0
|
0
|
|
|
|
|
if ( grep { /$elt/ } @country_values ) { |
|
0
|
|
|
|
|
|
|
311
|
0
|
|
|
|
|
|
$should_exclude = 1; |
312
|
0
|
|
|
|
|
|
last; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
0
|
0
|
|
|
|
|
if ( $should_exclude ) { |
317
|
0
|
|
|
|
|
|
next; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
0
|
0
|
|
|
|
|
if ( $data_key ) { |
322
|
0
|
|
|
|
|
|
push @return_countries, $country->{$data_key}; |
323
|
|
|
|
|
|
|
} else { |
324
|
0
|
|
|
|
|
|
push @return_countries, $country; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
|
328
|
0
|
|
|
|
|
|
return \@return_countries; |
329
|
|
|
|
|
|
|
} |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
1; |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
__END__ |