| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Locale::Geocode::Territory; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
47
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
122
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Locale::Geocode::Territory |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Locale::Geocode::Territory represents an individual |
|
13
|
|
|
|
|
|
|
country or territory as listed in ISO-3166-1. This |
|
14
|
|
|
|
|
|
|
class provides methods for returning information |
|
15
|
|
|
|
|
|
|
about the territory and any administrative divisions |
|
16
|
|
|
|
|
|
|
therein. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
To be listed in ISO-3166-1, a country or territory |
|
19
|
|
|
|
|
|
|
must be listed in the United Nations Terminology |
|
20
|
|
|
|
|
|
|
Bulletin Country Names or Country and Region Codes |
|
21
|
|
|
|
|
|
|
for Statistical Use of the UN Statistics Division. |
|
22
|
|
|
|
|
|
|
In order for a country or territory to be listed in |
|
23
|
|
|
|
|
|
|
the Country Names bulletin, one of the following |
|
24
|
|
|
|
|
|
|
must be true of the territory: |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
- is a United Nations member state a member |
|
27
|
|
|
|
|
|
|
- is a member of any of the UN specialized agencies |
|
28
|
|
|
|
|
|
|
- a party to the Statute of the International Court of Justice |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $lct = new Locale::Geocode::Territory 'US'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# lookup a subdivision of US |
|
35
|
|
|
|
|
|
|
my $lcd = $lct->lookup('TN'); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# retrieve ISO-3166-2 information for US-TN |
|
38
|
|
|
|
|
|
|
my $name = $lcd->name; # Tennessee |
|
39
|
|
|
|
|
|
|
my $code = $lcd->code; # TN |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# returns an array of Locale::Geocode::Division |
|
42
|
|
|
|
|
|
|
# objects representing all divisions of US |
|
43
|
|
|
|
|
|
|
my @divs = $lct->divisions; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use overload |
|
48
|
0
|
|
|
0
|
|
0
|
'""' => sub { return shift->alpha2 }, |
|
49
|
0
|
|
|
0
|
|
0
|
'==' => sub { return shift->num == shift->num }, |
|
50
|
1
|
|
|
1
|
|
7
|
'!=' => sub { return shift->num != shift->num }; |
|
|
1
|
|
|
0
|
|
2
|
|
|
|
1
|
|
|
|
|
15
|
|
|
|
0
|
|
|
|
|
0
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
1
|
|
|
1
|
|
851
|
use Locale::Geocode::Division; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
782
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item new |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
|
65
|
0
|
|
|
|
|
|
my $key = lc(shift); |
|
66
|
0
|
|
0
|
|
|
|
my $lg = shift || new Locale::Geocode; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
69
|
0
|
|
|
|
|
|
my $self = {}; |
|
70
|
0
|
|
|
|
|
|
$self->{lg} = $lg; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$self->{data} = Locale::Geocode::data()->{alpha2}->{$key} || |
|
73
|
|
|
|
|
|
|
Locale::Geocode::data()->{alpha3}->{$key} || |
|
74
|
|
|
|
|
|
|
Locale::Geocode::data()->{num}->{$key} || |
|
75
|
|
|
|
|
|
|
Locale::Geocode::data()->{name}->{$key}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
return undef if not defined $self->{data}; |
|
78
|
0
|
0
|
|
|
|
|
return undef if not $lg->chkext($self->{data}); |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return bless $self, $class; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item lg |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
1
|
|
sub lg { return shift->{lg} } |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item lookup |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub lookup |
|
94
|
|
|
|
|
|
|
{ |
|
95
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
96
|
0
|
|
|
|
|
|
my $key = shift; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return new Locale::Geocode::Division $key, $self; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item lookup_by_index |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub lookup_by_index |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
108
|
0
|
|
|
|
|
|
my $idx = shift; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return new Locale::Geocode::Division $self->{data}->{division}->[$idx], $self; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item name |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
0
|
1
|
|
sub name { return shift->{data}->{name} } |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item num |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
0
|
1
|
|
sub num { return shift->{data}->{num} } |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item alpha2 |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
0
|
1
|
|
sub alpha2 { return shift->{data}->{alpha2} } |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item alpha3 |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
0
|
1
|
|
sub alpha3 { return shift->{data}->{alpha3} } |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item fips |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
0
|
1
|
|
sub fips { return shift->{data}->{fips} } |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item has_notes |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub has_notes |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $data = $self->{data}; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
0
|
|
|
|
return $data->{note} && scalar @{ $data->{note} } > 0 ? 1 : 0 |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item num_notes |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub num_notes |
|
161
|
|
|
|
|
|
|
{ |
|
162
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $data = $self->{data}; |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
return $data->{note} ? scalar @{ $data->{note} } : 0; |
|
|
0
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item notes |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub notes |
|
174
|
|
|
|
|
|
|
{ |
|
175
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $data = $self->{data}; |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
return $data->{note} ? @{ $data->{note} } : (); |
|
|
0
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item note |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub note |
|
187
|
|
|
|
|
|
|
{ |
|
188
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
189
|
0
|
|
|
|
|
|
my $idx = shift; |
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my $data = $self->{data}; |
|
192
|
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
return $data->{note} ? $data->{note}->[$idx] : undef; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item divisions |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
returns an array of Locale::Geocode::Division objects |
|
199
|
|
|
|
|
|
|
representing all territorial divisions. this method |
|
200
|
|
|
|
|
|
|
honors the configured extensions. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub divisions |
|
205
|
|
|
|
|
|
|
{ |
|
206
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
0
|
|
|
|
|
return map { $self->lookup($_->{code}) || () } @{ $self->{data}->{division} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item divisions_sorted |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
the same as divisions, only all objects are sorted |
|
214
|
|
|
|
|
|
|
according to the specified metadata. if metadata |
|
215
|
|
|
|
|
|
|
is not specified (or is invalid), then all divisions |
|
216
|
|
|
|
|
|
|
are sorted by name. the supported metadata is any |
|
217
|
|
|
|
|
|
|
data-oriented method of Locale::Geocode::Division |
|
218
|
|
|
|
|
|
|
(name, code, fips, region, et alia). |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub divisions_sorted |
|
223
|
|
|
|
|
|
|
{ |
|
224
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
225
|
0
|
|
0
|
|
|
|
my $meta = lc shift || 'name'; |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
$meta = 'name' if not grep { $meta eq $_ } @Locale::Geocode::Division::meta; |
|
|
0
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
return sort { $a->$meta cmp $b->$meta } $self->divisions; |
|
|
0
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item num_divisions |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub num_divisions |
|
237
|
|
|
|
|
|
|
{ |
|
238
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
239
|
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
return scalar grep { $self->lg->chkext($_) } @{ $self->{data}->{division} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 AUTHOR |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Mike Eldridge |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 CREDITS |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Kim Ryan |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
L |
|
258
|
|
|
|
|
|
|
L |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=cut |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
1; |