File Coverage

blib/lib/Number/Phone/CountryCode.pm
Criterion Covered Total %
statement 18 18 100.0
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Number-Phone-CountryCode
3             #
4             # This software is copyright (c) 2009 by Michael Schout .
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9              
10             package Number::Phone::CountryCode;
11             $Number::Phone::CountryCode::VERSION = '0.03';
12             # ABSTRACT: DEPRECATED - Country Phone Dialing Prefixes
13              
14 2     2   1574 use strict;
  2         6  
  2         65  
15 2     2   14 use warnings;
  2         5  
  2         74  
16 2     2   13 use base qw(Class::Accessor);
  2         5  
  2         829  
17              
18             __PACKAGE__->mk_ro_accessors(qw(country
19             country_code
20             idd_prefix
21             ndd_prefix));
22              
23             warnings::warnif('deprecated',
24             'Number::Phone::CountryCode is deprecated. Please use Number::Phone::Country instead.');
25              
26             # Codes hash
27             # ISO code maps to 3 element array containing:
28             # - Country prefix
29             # - IDD prefix
30             # - NDD prefix
31             my %Codes = (
32             AD => ['376', '00', undef], # Andorra
33             AE => ['971', '00', '0'], # United Arab Emirates
34             AF => [ '93', '00', '0'], # Afghanistan
35             AG => [ '1', '011', '1'], # Antigua and Barbuda
36             AG => [ '1', '011', '1'], # Antigua and Barbuda
37             AI => [ '1', '011', '1'], # Anguilla
38             AL => ['355', '00', '0'], # Albania
39             AM => ['374', '00', '8'], # Armenia
40             AN => ['599', '00', '0'], # Netherlands Antilles
41             AO => ['244', '00', '0'], # Angola
42             AQ => ['672', undef, undef], # Antarctica
43             AR => [ '54', '00', '0'], # Argentina
44             AS => [ '1', '011', '1'], # American Samoa
45             AT => [ '43', '00', '0'], # Austria
46             AU => [ '61', '00', undef], # Australia
47             AW => ['297', '00', undef], # Aruba
48             AZ => ['994', '00', '8'], # Azerbaijan
49             BA => ['387', '00', '0'], # Bosnia and Herzegovina
50             BB => [ '1', '011', '1'], # Barbados
51             BD => ['880', '00', '0'], # Bangladesh
52             BE => [ '32', '00', '0'], # Belgium
53             BF => ['226', '00', undef], # Burkina Faso
54             BG => ['359', '00', '0'], # Bulgaria
55             BH => ['973', '00', undef], # Bahrain
56             BI => ['257', '00', undef], # Burundi
57             BJ => ['229', '00', undef], # Benin
58             BM => [ '1', '011', '1'], # Bermuda
59             BN => ['673', '00', '0'], # Brunei Darussalam
60             BO => ['591', '00', '0'], # Bolivia
61             BR => [ '55', '00', '0'], # Brazil
62             BS => [ '1', '011', '1'], # Bahamas
63             BT => ['975', '00', undef], # Bhutan
64             BV => [ '47', '00', undef], # Bouvet Island - Norway
65             BW => ['267', '00', undef], # Botswana
66             BY => ['375', '810', '8'], # Belarus (IDD really 8**10)
67             BZ => ['501', '00', '0'], # Belize
68             CA => [ '1', '011', '1'], # Canada
69             CC => [ '61', '0011', '0'], # Cocos (Keeling) Islands
70             CD => ['243', '00', undef], # Congo (Dem. Rep. of / Zaire)
71             CF => ['236', '00', undef], # Central African Republic
72             CG => ['242', '00', undef], # Congo
73             CH => [ '41', '00', '0'], # Switzerland
74             CI => ['225', '00', '0'], # Cote D'Ivoire
75             CK => ['682', '00', '00'], # Cook Islands
76             CL => [ '56', '00', '0'], # Chile
77             CM => ['237', '00', undef], # Cameroon
78             CN => [ '86', '00', '0'], # China
79             CO => [ '57', '009', '09'], # Colombia
80             CR => ['506', '00', undef], # Costa Rica
81             CU => [ '53', '119', '0'], # Cuba
82             CV => ['238', '0', undef], # Cape Verde Islands
83             CX => [ '61', '0011', '0'], # Christmas Island
84             CY => ['357', '00', undef], # Cyprus
85             CZ => ['420', '00', undef], # Czech Republic
86             DE => [ '49', '00', '0'], # Germany
87             DJ => ['253', '00', undef], # Djibouti
88             DK => [ '45', '00', undef], # Denmark
89             DM => [ '1', '011', 1], # Dominica
90             DO => [ '1', '011', 1], # Dominican Republic
91             DZ => ['213', '00', '7'], # Algeria
92             EC => ['593', '00', '0'], # Ecuador
93             EE => ['372', '00', undef], # Estonia
94             EG => [ '20', '00', '0'], # Egypt
95             EH => ['212', '00', '0'], # Western Sahara
96             ER => ['291', '00', '0'], # Eritrea
97             ES => [ '34', '00', undef], # Spain
98             ET => ['251', '00', '0'], # Ethiopia
99             FI => ['358', '00', '0'], # Finland
100             FJ => ['679', '00', undef], # Fiji
101             FK => ['500', '00', undef], # Falkland Islands (Malvinas)
102             FM => ['691', '011', '1'], # Micronesia, Federated States of
103             FO => ['298', '00', undef], # Faroe Islands
104             FR => [ '33', '00', undef], # France
105             GA => ['241', '00', undef], # Gabonese Republic
106             GB => [ '44', '00', '0'], # United Kingdom
107             GD => [ '1', '011', '4'], # Grenada
108             GE => ['995', '810', '8'], # Georgia
109             GF => ['594', '00', undef], # French Guiana
110             GH => ['233', '00', undef], # Ghana
111             GI => ['350', '00', undef], # Gibraltar
112             GL => ['299', '00', undef], # Greenland
113             GM => ['220', '00', undef], # Gambia
114             GN => ['224', '00', '0'], # Guinea
115             GP => ['590', '00', undef], # Guadeloupe
116             GQ => ['240', '00', undef], # Equatorial Guinea
117             GR => [ '30', '00', undef], # Greece
118             GS => ['995', '810', '8'], # South Georgia and the South Sandwich Islands (IDD really 8**10)
119             GT => ['502', '00', undef], # Guatemala
120             GU => [ '1', '011', '1'], # Guam
121             GW => ['245', '00', undef], # Guinea-Bissau
122             GY => ['592', '001', '0'], # Guyana
123             HK => ['852', '001', undef], # Hong Kong
124             HM => ['692', '00', '0'], # Heard Island & McDonald Islands
125             HN => ['504', '00', '0'], # Honduras
126             HR => ['385', '00', '0'], # Croatia
127             HT => ['509', '00', '0'], # Haiti
128             HU => [ '36', '00', '06'], # Hungary
129             ID => [ '62', '001', '0'], # Indonesia
130             IE => ['353', '00', '0'], # Ireland
131             IL => ['972', '00', '0'], # Israel
132             IN => [ '91', '00', '0'], # India
133             IO => ['246', '00', undef], # British Indian Ocean Territory
134             IQ => ['964', '00', '0'], # Iraq
135             IR => [ '98', '00', '0'], # Iran, Islamic Republic of
136             IS => ['354', '00', '0'], # Iceland
137             IT => [ '39', '00', undef], # Italy
138             JM => [ '1', '011', '1'], # Jamaica
139             JO => ['962', '00', '0'], # Jordan
140             JP => [ '81', '001', '0'], # Japan
141             KE => ['254', '000', '0'], # Kenya
142             KG => ['996', '00', '0'], # Kyrgyzstan
143             KH => ['855', '001', '0'], # Cambodia
144             KI => ['686', '00', '0'], # Kiribati
145             KM => ['269', '00', undef], # Comoros
146             KN => [ '1', '011', '1'], # Saint Kitts and Nevis
147             KP => ['850', '00', '0'], # Korea, Democratic People's Republic of
148             KR => [ '82', '001', '0'], # Korea (South)
149             KW => ['965', '00', '0'], # Kuwait
150             KY => [ '1', '011', '1'], # Cayman Islands
151             KZ => [ '7', '810', '8'], # Kazakhstan (IDD really 8**10)
152             LA => ['856', '00', '0'], # Laos
153             LB => ['961', '00', '0'], # Lebanon
154             LC => [ '1', '011', '1'], # Saint Lucia
155             LI => ['423', '00', undef], # Liechtenstein
156             LK => [ '94', '00', '0'], # Sri Lanka
157             LR => ['231', '00', '22'], # Liberia
158             LS => ['266', '00', '0'], # Lesotho
159             LT => ['370', '00', '8'], # Lithuania
160             LU => ['352', '00', undef], # Luxembourg
161             LV => ['371', '00', '8'], # Latvia
162             LY => ['218', '00', '0'], # Libyan Arab Jamahiriya
163             MA => ['212', '00', undef], # Morocco
164             MC => ['377', '00', '0'], # Monaco
165             MD => ['373', '00', '0'], # Moldova, Republic of
166             ME => ['382', '99', '0'], # Montenegro
167             MG => ['261', '00', '0'], # Madagascar
168             MH => ['692', '011', '1'], # Marshall Islands
169             MK => ['389', '00', '0'], # Macedonia, the Former Yugoslav Republic of
170             ML => ['223', '00', '0'], # Mali
171             MM => [ '95', '00', undef], # Myanmar
172             MN => ['976', '001', '0'], # Mongolia
173             MO => ['853', '00', '0'], # Macao
174             MP => [ '1', '011', '1'], # Northern Mariana Islands
175             MQ => ['596', '00', '0'], # Martinique
176             MR => ['222', '00', '0'], # Mauritania
177             MS => [ '1', '011', '1'], # Montserrat
178             MT => ['356', '00', '21'], # Malta
179             MU => ['230', '00', '0'], # Mauritius
180             MV => ['960', '00', '0'], # Maldives
181             MW => ['265', '00', undef], # Malawi
182             MX => [ '52', '00', '01'], # Mexico
183             MY => [ '60', '00', '0'], # Malaysia
184             MZ => ['258', '00', '0'], # Mozambique
185             NA => ['264', '00', '0'], # Namibia
186             NC => ['687', '00', '0'], # New Caledonia
187             NE => ['227', '00', '0'], # Niger
188             NF => ['672', '00', undef], # Norfolk Island
189             NG => ['234', '009', '0'], # Nigeria
190             NI => ['505', '00', '0'], # Nicaragua
191             NL => [ '31', '00', '0'], # Netherlands
192             NO => [ '47', '00', undef], # Norway
193             NP => ['977', '00', '0'], # Nepal
194             NR => ['674', '00', '0'], # Nauru
195             NU => ['683', '00', '0'], # Niue
196             NZ => [ '64', '00', '0'], # New Zealand
197             OM => ['968', '00', '0'], # Oman
198             PA => ['507', '00', '0'], # Panama
199             PE => [ '51', '00', '0'], # Peru
200             PF => ['689', '00', undef], # French Polynesia
201             PG => ['675', '05', undef], # Papua New Guinea
202             PH => [ '63', '00', '0'], # Philippines
203             PK => [ '92', '00', '0'], # Pakistan
204             PL => [ '48', '00', '0'], # Poland
205             PM => ['508', '00', '0'], # Saint Pierre and Miquelon
206             PN => ['872', undef, undef], # Pitcairn
207             PR => [ '1', '011', '1'], # Puerto Rico
208             PS => ['970', '00', '0'], # Palestinian Territory, Occupied
209             PT => ['351', '00', undef], # Portugal
210             PW => ['680', '011', undef], # Palau
211             PY => ['595', '002', '0'], # Paraguay
212             QA => ['974', '00', '0'], # Qatar
213             RE => ['262', '00', '0'], # Reunion
214             RO => [ '40', '00', '0'], # Romania
215             RS => ['381', '99', '0'], # Serbia
216             RU => [ '7', '810', '8'], # Russia 8**10 NOTE: may change to 00, 0
217             RW => ['250', '00', '0'], # Rwanda
218             SA => ['966', '00', '0'], # Saudi Arabia
219             SB => ['677', '00', undef], # Solomon Islands
220             SC => ['248', '00', '0'], # Seychelles
221             SD => ['249', '00', '0'], # Sudan
222             SE => [ '46', '00', '0'], # Sweden
223             SG => [ '65', '001', undef], # Singapore
224             SH => ['290', '00', undef], # Saint Helena
225             SI => ['386', '00', '0'], # Slovenia
226             SJ => ['378', '00', '0'], # Svalbard and Jan Mayen
227             SK => ['421', '00', '0'], # Slovakia
228             SL => ['232', '00', '0'], # Sierra Leone
229             SM => ['378', '00', '0'], # San Marino
230             SN => ['221', '00', '0'], # Senegal
231             SO => ['252', '00', undef], # Somalia
232             SR => ['597', '00', undef], # Suriname
233             ST => ['239', '00', '0'], # Sao Tome and Principe
234             SV => ['503', '00', undef], # El Salvador
235             SY => ['963', '00', '0'], # Syria
236             SZ => ['268', '00', undef], # Swaziland
237             TC => [ '1', '011', '1'], # Turks and Caicos Islands
238             TD => ['235', '15', undef], # Chad
239             TF => ['596', '00', '0'], # French Southern Territories
240             TG => ['228', '00', undef], # Togo
241             TH => [ '66', '001', '0'], # Thailand
242             TJ => ['992', '810', '8'], # Tajikistan (IDD really 8**10)
243             TK => ['690', '00', undef], # Tokelau
244             TL => ['670', '00', undef], # Timor-Leste
245             TM => ['993', '810', '8'], # Turkmenistan (IDD really 8**10)
246             TN => ['216', '00', '0'], # Tunisia
247             TO => ['676', '00', undef], # Tonga Islands
248             TR => [ '90', '00', '0'], # Turkey
249             TT => [ '1', '011', '1'], # Trinidad and Tobago
250             TV => ['688', '00', undef], # Tuvalu
251             TW => ['886', '002', undef], # Taiwan, Province of China
252             TZ => ['255', '000', '0'], # Tanzania, United Republic of
253             UA => ['380', '810', '8'], # Ukraine (IDD really 8**10)
254             UG => ['256', '000', '0'], # Uganda
255             US => [ '1', '011', '1'], # United States
256             UY => ['598', '00', '0'], # Uruguay
257             UZ => ['998', '810', '8'], # Uzbekistan (IDD really 8**10)
258             VA => ['379', '00', undef], # Holy See (Vatican City State)
259             VC => [ '1', '011', '1'], # Saint Vincent and the Grenadines
260             VE => [ '58', '00', '0'], # Venezuela
261             VG => [ '1', '011', '1'], # Virgin Islands, British
262             VI => [ '1', '011', '1'], # Virgin Islands, U.S.
263             VN => [ '84', '00', '0'], # Viet Nam
264             VU => ['678', '00', undef], # Vanuatu
265             WF => ['681', '19', undef], # Wallis and Futuna Islands
266             WS => ['685', '0', '0'], # Samoa (Western)
267             YE => ['967', '00', '0'], # Yemen
268             YT => ['269', '00', undef], # Mayotte
269             ZA => [ '27', '09', '0'], # South Africa
270             ZM => ['260', '00', '0'], # Zambia
271             ZW => ['263', '110', '0'], # Zimbabwe
272             );
273              
274              
275             sub new {
276 240     240 1 759848 my ($class, $country) = @_;
277              
278 240         767 $country = uc $country;
279              
280 240         826 my $data = $Codes{$country};
281              
282             # return nothing if no data for this country code.
283 240 50       852 return unless defined $data;
284              
285 240         1925 return $class->SUPER::new({
286             country => $country,
287             country_code => $data->[0],
288             idd_prefix => $data->[1],
289             ndd_prefix => $data->[2]
290             });
291             }
292              
293              
294             sub countries {
295 1     1 1 175 return sort keys %Codes;
296             }
297              
298              
299             sub is_supported {
300 2     2 1 3301 my ($class, $code) = @_;
301              
302 2         8 $code = uc $code;
303              
304 2 100       20 return defined $Codes{$code} ? 1 : 0;
305             }
306              
307             1;
308              
309             __END__