diff --git a/.github/workflows/install-dist.yml b/.github/workflows/install-dist.yml new file mode 100644 index 0000000..9a79b78 --- /dev/null +++ b/.github/workflows/install-dist.yml @@ -0,0 +1,57 @@ +on: [push, pull_request] +name: Dist installation + +jobs: + build: + runs-on: 'macos-10.15' + steps: + - uses: actions/checkout@v2 + - name: Setup Perl environment + uses: shogo82148/actions-setup-perl@v1 + - name: Test and build + run: | + cpanm --quiet --notest ExtUtils::MakeMaker Test::Pod Test::Pod::Coverage parent + cpanm --quiet --notest File::ShareDir::Install XML::XPath DBM::Deep Digest::MD5 + cpanm --quiet --notest File::Find::Rule Spreadsheet::XLSX Text::CSV_XS LWP::Protocol::https + cpanm --quiet --notest --installdeps . + perl Makefile.PL + ./build-data.sh + make test + make dist + - uses: actions/upload-artifact@v2 + with: + name: dist-for-installation-test + path: '*.tar.gz' + retention-days: 1 + install-linux: + runs-on: 'ubuntu-latest' + needs: build + container: + image: perl:5.34 + steps: + - uses: actions/download-artifact@v2 + with: + name: dist-for-installation-test + - name: Install on Linux + run: | + cpanm *.tar.gz + install-openbsd: + runs-on: macos-10.15 + needs: build + steps: + - uses: actions/download-artifact@v2 + with: + name: dist-for-installation-test + - name: Install on OpenBSD + uses: cross-platform-actions/action@v0.3.1 + with: + operating_system: openbsd + version: 6.9 + shell: bash + run: | + mkdir dist-for-test && + tar -C dist-for-test -xzf *.tar.gz && + cd dist-for-test/* && + cpan App::cpanminus && + /home/runner/perl5/bin/cpanm --quiet --notest --installdeps . && + /home/runner/perl5/bin/cpanm -v . diff --git a/.github/workflows/linux-without_uk-build.yml b/.github/workflows/linux-without_uk-build.yml index 8737254..de2e856 100644 --- a/.github/workflows/linux-without_uk-build.yml +++ b/.github/workflows/linux-without_uk-build.yml @@ -26,7 +26,7 @@ jobs: cpanm --quiet --notest Data::Dumper::Concise File::ShareDir::Install XML::XPath Data::CompactReadonly Digest::MD5 File::Find::Rule Spreadsheet::XLSX Text::CSV_XS LWP::Protocol::https cpanm --quiet --notest --installdeps . ./build-data.sh - perl Makefile.PL --without_uk + perl Makefile.PL --without_uk INSTALL_BASE=$HOME/test_install make test TEST_VERBOSE=1 make install - perl -MData::Dumper::Concise -MNumber::Phone -e 'if(Number::Phone->new("+447979866975")->isa("Number::Phone::StubCountry::GB")) { print "N::P built/installed correctly without N::P::UK\n".Dumper(\%INC); exit(0) } else { print "N::P build/install failed\n"; exit(1) }' + perl -I$HOME/test_install/lib/perl5 -MData::Dumper::Concise -MNumber::Phone -e 'if(Number::Phone->new("+447979866975")->isa("Number::Phone::StubCountry::GB")) { print "N::P built/installed correctly without N::P::UK\n".Dumper(\%INC); exit(0) } else { print "N::P build/install failed\n"; exit(1) }' diff --git a/CHANGELOG b/CHANGELOG index 7c9ad98..3190721 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,58 @@ -XXXX-XX-XX XXXXXX Switch to Data::CompactReadonly for UK database +XXXXXX XXXX-XX-XX -XXXX-XX-XX XXXXXX Data updates; - Add deprecation warning for platforms with 32 bit int (support will - go away some time after 2023-06-01 with no further warning) +- Switch to Data::CompactReadonly for UK database + +3.8004 2022-03-07 + +- Fix test failure that only occurred if Number::Phone::JP was installed + (it doesn't have exactly the data we expect from ...::StubCountry::JP) + +- Data updates from OFCOM + +3.8003 2022-03-05 + +- New Canadian area codes +- +882 34 recognised as Antarctica, via Global Networks Switzerland + +3.8002 2021-12-06 + +- Fix Makefile.PL to not consume arguments that my code doesn't know about but + which are relevant to EU::MM (https://github.com/DrHyde/perl-modules-Number-Phone/pull/106) + +- Explicitly open databases read-only so it works on a RO filesystem + (https://github.com/DrHyde/perl-modules-Number-Phone/issues/107) + +- Data updates + +3.8001 2021-09-21 + +- Tweak build to use more compatible options to tar(1) so some really old tars + can read the archive correctly + +3.8000 2021-09-19 + +- Bugfix for numbers in local format which may be ambiguous for UK Crown Dependencies + when using Number::Phone::Lib + +- Bugfix for when you ask for an object representing a number in one country + but provide a number for a different country. This mostly affects countries + that contain other jurisdictions squatting on parts of their number plan, + such as the Vatican in the Italian plan, and the Crown Dependencies in the UK + plan. It is now an error to ask for an object representing a number in a + 'sub-country' which isn't valid in that sub-country (eg asking for a Jersey + object but passing a Guernsey number); but if you ask for an object representing + the 'super-country' but pass a 'sub-country' number you'll still get an object + representing the sub-country. ie, say "gimme a GB object for this 'ere Guernsey number" + and you'll get a Guernsey object. + +- Data updates + +3.7003 2021-06-02 + +- Data updates; + +- Add deprecation warning for platforms with 32 bit int (support will + go away some time after 2023-06-01 with no further warning) 2021-03-09 3.7002 Data updates diff --git a/MANIFEST b/MANIFEST index 6bd3fdc..b932ef1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -95,6 +95,8 @@ t/source_data.t buildtools/Number/Phone/BuildTools.pm t/manifest-contains-all-modules.t t/only-use-blib-under-make-test.t +t/deprecations.t +t/constructor.t lib/Number/Phone/StubCountry/AC.pm lib/Number/Phone/StubCountry/AD.pm lib/Number/Phone/StubCountry/AE.pm diff --git a/Makefile.PL b/Makefile.PL index 629b1b0..b988180 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -11,8 +11,8 @@ BEGIN { shift @INC; } -while(@ARGV) { - if(shift() eq '--without_uk') { +foreach my $arg (@ARGV) { + if($arg eq '--without_uk') { $Number::Phone::BuildTools::without_uk++; } } @@ -32,7 +32,7 @@ WriteMakefile( }, VERSION_FROM => 'lib/Number/Phone.pm', BUILD_REQUIRES => { - 'ExtUtils::MakeMaker' => 6.52, + 'ExtUtils::MakeMaker' => 6.64, # TEST_REQUIRES (CONFIGURE_REQUIRES is in 6.52; BUILD_REQUIRES in 6.56) 'ExtUtils::Manifest' => 0, 'ExtUtils::Install' => 0, 'File::ShareDir::Install' => 0.11, @@ -40,12 +40,11 @@ WriteMakefile( }, CONFIGURE_REQUIRES => { - 'ExtUtils::MakeMaker' => 6.52, + 'ExtUtils::MakeMaker' => 6.64, 'ExtUtils::Manifest' => 0, 'ExtUtils::Install' => 0, 'File::ShareDir::Install' => 0.11 }, - PREREQ_PM => { 'Cwd' => 0, 'Data::CompactReadonly' => '0.0.3', @@ -59,13 +58,18 @@ WriteMakefile( 'I18N::LangTags' => 0, 'I18N::LangTags::Detect' => 0, 'Scalar::Util' => 1.48, + }, + TEST_REQUIRES => { + 'Carp' => 0, 'Test::Differences' => 0.62, 'Test::More' => '0.96', # need done_testing (0.88) and subtests (0.95_01) - 'Test::utf8' => 0, 'Test::Warnings' => 0, + 'Devel::Hide' => 0, + 'if' => 0, }, dist => { - PREOP => "./build-data.sh --previouslibphonenumbertag" + PREOP => "./build-data.sh --previouslibphonenumbertag", + TARFLAGS => "--format ustar -c -v -f", }, realclean => { FILES => "cover_db" diff --git a/build-data.country-mapping b/build-data.country-mapping index 94c9053..4446c39 100644 --- a/build-data.country-mapping +++ b/build-data.country-mapping @@ -146,8 +146,8 @@ foreach my $tuple ( [ 672 => ['AQ', 'NF' ]], # no AQ in libphonenumber [ 7 => ['RU', 'KZ' ]], - # checked on 2020-12-04 - # next check due 2021-12-01 (annually) + # checked on 2021-12-06 + # next check due 2022-12-01 (annually) [ 2125288 => 'EH' ], # see https://en.wikipedia.org/wiki/Telephone_numbers_in_Western_Sahara [ 2125289 => 'EH' ], # see https://en.wikipedia.org/wiki/Telephone_numbers_in_Western_Sahara [ 262269 => 'YT' ], # Mayotte fixed lines, see http://www.wtng.info/wtng-262-fr.html @@ -158,33 +158,61 @@ foreach my $tuple ( [ 390549 => 'SM' ], # San Marino in Italian dialling plan, see https://en.wikipedia.org/wiki/Telephone_numbers_in_San_Marino # sourced from libphonenumber - # checked on 2020-12-04 - # next check due 2021-12-01 (annually) - [ 441481 => 'GG' ], - [ 447781 => 'GG' ], - [ 447839 => 'GG' ], - [ 447911 => 'GG' ], - [ 441624 => 'IM' ], - [ 447457 => 'IM' ], - [ 4474576 => 'IM' ], - [ 447524 => 'IM' ], - [ 447624 => 'IM' ], - [ 447924 => 'IM' ], - [ 441534 => 'JE' ], - [ 447509 => 'JE' ], - [ 447829 => 'JE' ], - [ 447937 => 'JE' ], - [ 447700 => 'JE' ], - [ 447797 => 'JE' ], + # checked on 2021-09-02 + # next check due 2022-09-01 (annually) + ( + map { + [ '44'.$_ => 'GG' ] + } ( + 1481, 7781, 7839, 79111, 79117 + ) + ), + ( + map { + [ '44'.$_ => 'IM' ] + } ( + 1624, + 74576, + 7524, + 76240, + 76241, + 76242, + 76243, + 76244, + 762450, + 762456, + 76246, + 76248, + 76249, + 7924, + 808162, + 8440406, 8440906, + 845624, 870624, + 872299, + 900624, 901624, 906624, 907624, + ) + ), + ( + map { + [ '44'.$_ => 'JE' ] + } ( + 1534, 7509, 7829, 7937, + 77003, + 77007, + 77008, + 7797, + ) + ), # see https://en.wikipedia.org/wiki/Telephone_numbers_in_Cura%C3%A7ao_and_the_Caribbean_Netherlands # see https://en.wikipedia.org/wiki/Cocos_(Keeling)_Islands#Communications # NB the company listed there for +61 406 went bust # see http://wtng.info/ccod-6.html#CC61 (Christmas Island) + # 2G mobile only, no data: https://parksaustralia.gov.au/christmas/plan/phone-web/ # see https://en.wikipedia.org/wiki/Telephone_numbers_in_the_Australian_Antarctic_Territory # see https://en.wikipedia.org/wiki/Telephone_numbers_in_Norfolk_Island - # checked on 2020-12-04 - # next check due 2021-12-01 (annually) + # checked on 2021-12-0r64 + # next check due 2022-12-01 (annually) [ 5999 => 'CW' ], # Curacao [ 6189162 => 'CC' ], # Cocos (Keeling) Islands [ 6189164 => 'CX' ], # Christmas Island @@ -196,8 +224,9 @@ foreach my $tuple ( [ 6723 => 'NF' ], # Norfolk Island # see http://en.wikipedia.org/wiki/Telephone_numbers_in_Kazakhstan - # checked on 2020-12-04 - # next check due 2022-12-01 (bi-annually) + # NB planned change to +997 + # checked on 2021-12-06 + # next check due 2022-12-01 (annually) [ 76 => 'KZ' ], [ 77 => 'KZ' ], @@ -219,8 +248,8 @@ foreach my $tuple ( # see https://en.wikipedia.org/wiki/Global_Mobile_Satellite_System # https://en.wikipedia.org/wiki/International_Networks_%28country_code%29 # wtng.info - # checked on 2019-12-11 - # next check due 2021-12-01 (bi-annually) + # checked on 2022-03-04 + # next check due 2024-12-01 (bi-annually) [ 800 => 'InternationalFreephone' ], [ 808 => 'SharedCostServices' ], [ 870 => 'Inmarsat' ], @@ -233,8 +262,8 @@ foreach my $tuple ( [ 881 => 'GMSS', ], # \ Sat-phones [ 8810 => 'ICO', ], # | [ 8811 => 'ICO', ], # | - # 8812 and 8813 assigned to Ellipso # | - # but that apparently never launched # | + # 8812 is vacant (Ellipso never launched) # | + # 8813 is vacant (Ellipso never launched) # | # 8814 is spare # | # 8815 is spare # | [ 8816 => 'Iridium', ], # | @@ -242,14 +271,15 @@ foreach my $tuple ( [ 8818 => 'Globalstar', ], # | [ 8819 => 'Globalstar', ], # / [ 882 => 'InternationalNetworks' ], # many allocations not listed as I don't know if they're diallable, see wtng.info - [ 88213 => 'Telespazio' ], # Sat-ohone + [ 88213 => 'Telespazio' ], # Sat-phone [ 88216 => 'Thuraya' ], # Sat-phone [ 88220 => 'GarudaMobile' ], # Sat-phone + [ 88234 => 'AQ' ], # Antarctica, via Global Networks Switzerland, http://wtng.info/wtng-spe.html#Networks [ 883 => 'InternationalNetworks' ], [ 883120 => 'Telenor' ], [ 883130 => 'Mobistar' ], [ 883140 => 'MTTGlobalNetworks' ], - [ 8835100 => 'VOXBON' ], + # 8835100 => 'VOXBON' # decommissioned, https://en.wikipedia.org/wiki/International_Networks_%28country_code%29 [ 888 => 'TelecomsForDisasterRelief' ], # 979 is used for testing when we fail to load a module when we # know what "country" it is diff --git a/build-data.sh b/build-data.sh index 2506383..0fa408c 100755 --- a/build-data.sh +++ b/build-data.sh @@ -22,6 +22,9 @@ LIBPHONENUMBERTAG=unset FORCE=0 EXITSTATUS=0 +# some machines have one of 'em, some have t'other +MD5=$(which md5 || which md5sum) + # now get an up-to-date libphonenumber and data-files ( (cd libphonenumber || (echo Checking out libphonenumber ...; git clone https://github.com/googlei18n/libphonenumber.git)) @@ -75,41 +78,43 @@ fi echo $LIBPHONENUMBERTAG > .libphonenumber-tag # first get OFCOM data and NANP operator data +# OFCOM data was found at: +# https://www.ofcom.org.uk/phones-telecoms-and-internet/information-for-industry/numbering/numbering-data +# (prev at http://static.ofcom.org.uk/static/numbering/) # NANP data was found at: -# https://www.nationalnanpa.com/reports/reports_cocodes_assign.html -# https://www.nationalnanpa.com/reports/reports_cocodes.html -# http://cnac.ca/co_codes/co_code_status.htm +# https://www.nationalnanpa.com/reports/reports_cocodes_assign.html +# https://www.nationalnanpa.com/reports/reports_cocodes.html +# http://cnac.ca/co_codes/co_code_status.htm ( cd data-files for i in \ - http://static.ofcom.org.uk/static/numbering/sabc.txt \ - http://static.ofcom.org.uk/static/numbering/sabcde11_12.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde13.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde14.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde15.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde16.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde17.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde18.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde19.xlsx \ - http://static.ofcom.org.uk/static/numbering/sabcde2.xlsx \ - http://static.ofcom.org.uk/static/numbering/S3.xlsx \ - http://static.ofcom.org.uk/static/numbering/S5.xlsx \ - http://static.ofcom.org.uk/static/numbering/S7.xlsx \ - http://static.ofcom.org.uk/static/numbering/S8.xlsx \ - http://static.ofcom.org.uk/static/numbering/S9.xlsx \ - https://www.nationalpooling.com/reports/region/AllBlocksAugmentedReport.zip \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0029/227747/sabcde11_12.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0031/227749/sabcde13.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0024/227751/sabcde14.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0026/227753/sabcde15.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0028/227755/sabcde16.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0030/227757/sabcde17.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0032/227759/sabcde18.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0025/227761/sabcde19.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0027/227745/sabcde2.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0024/227733/S3.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0026/227735/S5.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0028/227737/S7.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0030/227739/S8.xlsx \ + https://www.ofcom.org.uk/__data/assets/excel_doc/0023/227741/S9.xlsx \ + https://www.nationalpooling.com/reports/region/AllBlocksAugmentedReport.zip \ https://cnac.ca/data/COCodeStatus_ALL.zip; do # make sure that there's a file that curl -z can look at if test ! -e `basename $i`; then touch -t 198001010101 `basename $i` fi - echo Fetching $i + echo -n Fetching $i ... curl -z `basename $i` -R -O -s -S $i; if [ "$?" == "0" ]; then - echo " ... OK" + echo " OK" else - echo " ... failed with $?, retry" + echo " failed with $?, retry" sleep 15 rm `basename $i` curl -R -O -s -S $i; @@ -135,13 +140,25 @@ echo $LIBPHONENUMBERTAG > .libphonenumber-tag ) # stash the Unix epoch of the OFCOM data -OFCOMDATETIME=$(cd data-files;perl -e 'print +(stat(shift))[9]' $(ls -rt sabc.txt *.xlsx|tail -1)) +OFCOMDATETIME=$(cd data-files;perl -e 'print +(stat(shift))[9]' $(ls -rt *.xlsx|tail -1)) CADATETIME=$(cd data-files;perl -e 'print +(stat(shift))[9]' COCodeStatus_ALL.csv) USDATETIME=$(cd data-files;perl -e 'print +(stat(shift))[9]' AllBlocksAugmentedReport.txt) -# if share/Number-Phone-UK-Data.db doesn't exist, or OFCOM's stuff is newer ... +# whine/quit if any of those are older than three months +CURRENTDATETIME=$(date +%s) +THREEMONTHS=7776000 +if [ $(( $CURRENTDATETIME - $OFCOMDATETIME )) -gt $THREEMONTHS -o \ + $(( $CURRENTDATETIME - $CADATETIME )) -gt $THREEMONTHS -o \ + $(( $CURRENTDATETIME - $USDATETIME )) -gt $THREEMONTHS \ + ]; then + echo Data files are ANCIENT, check that the URLs are correct + exit 1 +fi + +# if share/Number-Phone-UK-Data.db doesn't exist, or OFCOM's stuff or +# libphonenumber's list of area codes is newer ... if test ! -e share/Number-Phone-UK-Data.db -o \ - data-files/sabc.txt -nt share/Number-Phone-UK-Data.db -o \ + libphonenumber/resources/geocoding/en/44.txt -nt share/Number-Phone-UK-Data.db -o \ data-files/sabcde11_12.xlsx -nt share/Number-Phone-UK-Data.db -o \ data-files/sabcde13.xlsx -nt share/Number-Phone-UK-Data.db -o \ data-files/sabcde14.xlsx -nt share/Number-Phone-UK-Data.db -o \ @@ -236,7 +253,7 @@ else fi # update Number::Phone::Data with update date/times and libphonenumber tag -OLD_N_P_DATA_MD5=$(md5sum lib/Number/Phone/Data.pm 2>/dev/null) +OLD_N_P_DATA_MD5=$($MD5 lib/Number/Phone/Data.pm 2>/dev/null) ( echo \# automatically generated file, don\'t edit echo package Number::Phone::Data\; @@ -265,7 +282,7 @@ OLD_N_P_DATA_MD5=$(md5sum lib/Number/Phone/Data.pm 2>/dev/null) echo echo =cut )>lib/Number/Phone/Data.pm -if [ "$OLD_N_P_DATA_MD5" != "$(md5sum lib/Number/Phone/Data.pm)" ] && [ "$CI" != "True" ] && [ "$CI" != "true" ]; then +if [ "$OLD_N_P_DATA_MD5" != "$($MD5 lib/Number/Phone/Data.pm)" ] && [ "$CI" != "True" ] && [ "$CI" != "true" ]; then EXITSTATUS=1 fi diff --git a/build-data.stubs b/build-data.stubs index bdd1068..5d148d1 100644 --- a/build-data.stubs +++ b/build-data.stubs @@ -46,6 +46,9 @@ TERRITORY: foreach my $territory (@territories) { my $national_code = ''.$territory->find('@nationalPrefixForParsing') || ''.$territory->find('@nationalPrefix'); my $national_prefix_transform_rule = ''.$territory->find('@nationalPrefixTransformRule'); + # see https://github.com/DrHyde/perl-modules-Number-Phone/issues/101 + $national_prefix_transform_rule = '' if($IDD_country_code == 44); + my $ISO_country_code = ''.$territory->find('@id'); if($ISO_country_code !~ /^..$/) { warn("skipping 'country' $ISO_country_code (+$IDD_country_code)\n"); diff --git a/build-data.uk b/build-data.uk index 4a7db54..93c6293 100644 --- a/build-data.uk +++ b/build-data.uk @@ -7,23 +7,17 @@ use Data::CompactReadonly; use Digest::MD5 'md5_base64'; use File::Find::Rule; use Spreadsheet::XLSX; -use Text::CSV_XS; - -my $csv = Text::CSV_XS->new({ - binary => 1 -}); my @telco_length_data = my @geo_prefices = my @free_prefices = my @network_svc_prefices = my @corporate_prefices = my @personal_prefices = my @pager_prefices = my @mobile_prefices = my @special_prefices = my @adult_prefices = my @ip_prefices = my %areanames = my %statuses = (); -open(my $sabc, '<', 'data-files/sabc.txt') || die("Couldn't open sabc.txt: $!\n"); -print "Working on sabc.txt\n"; -while(my $row = $csv->getline($sabc)) { - next if($#{$row} == 0 && $row->[0] =~ m{^\d\d/\d\d/\d{4} \d\d:\d\d:\d\d$}); - my @fields = @{$row}; - next if($fields[3] =~ /(unassigned|not to be used|expansion$)/i || $fields[2] eq 'Not Designated'); - if($fields[2] eq 'Designated' && $fields[3] !~ /^Geographic - unassigned/) { - $areanames{$fields[0]} = $fields[3]; - } +open(my $area_codes, '<', 'libphonenumber/resources/geocoding/en/44.txt') || die("Couldn't open libphonenumber/resources/geocoding/en/44.txt: $!\n"); +print "Working on libphonenumber/resources/geocoding/en/44.txt\n"; +while(my $line = <$area_codes>) { + chomp($line) if($line); + next if(!$line || $line =~ /^#/); + my @row = split(/\|/, $line); + $row[0] =~ s/^44//; + $areanames{$row[0]} = $row[1]; } foreach my $xlsfile (File::Find::Rule->name('*.xlsx')->in('data-files')) { @@ -77,7 +71,13 @@ foreach my $xlsfile (File::Find::Rule->name('*.xlsx')->in('data-files')) { $telco ||= ''; $format ||= ''; - next if($status !~ /^(Protected|Allocated ?(\(Closed Range\)|for Migration only)?)$/); + # checked on 2021-06-01 + # next check due 2022-06-01 (annually) + next if( + $prefix !~ /^11[46]496$/ && # These drama prefixex have status 'Quarantined' + # unlike other drama prefixes which are 'Protected' + $status !~ /^(Protected|Allocated ?(\(Closed Range\)|for Migration only)?)$/ + ); $statuses{"$prefix"} = $status; if($prefix =~ /^[12]/) { push @geo_prefices, $prefix } @@ -165,25 +165,39 @@ Data::CompactReadonly->create( special_prefices => { map { ($_, 1) } @special_prefices }, adult_prefices => { map { ($_, 1) } @adult_prefices }, ip_prefices => { map { ($_, 1) } @ip_prefices }, - areanames => { map { s/( National Dialling)//ig; $_; } %areanames }, + areanames => \%areanames, telco_format => \%telco_format_cache, telco_and_length => \%telco_and_length, subclass => { - # special case, UK-wide mobile range for use in drama, - # conflicts with 7700 being Jersey below - '7700900' => '', # taken from libphonenumber - # checked on 2020-09-04 - # next check due 2021-09-01 (annually) + # checked on 2021-09-02 + # next check due 2022-09-01 (annually) + # NB for all of these also check build-data.country-mapping (map { $_ => 'GG' } ( - 1481, 7781, 7839, 7911 + 1481, 7781, 7839, 79111, 79117 )), (map { $_ => 'JE' } ( - 1534, 7509, 7829, 7937, 7700, 7797 + 1534, 7509, 7829, 7937, + 77003, + 77007, + 77008, + 7797, )), (map { $_ => 'IM' } ( 1624, - 74576, 7524, 7624, 7924, + 74576, + 7524, + 76240, + 76241, + 76242, + 76243, + 76244, + 762450, + 762456, + 76246, + 76248, + 76249, + 7924, 808162, 8440406, 8440906, 845624, 870624, diff --git a/build-tests.pl b/build-tests.pl index 07988fd..3756858 100644 --- a/build-tests.pl +++ b/build-tests.pl @@ -147,6 +147,9 @@ $class eq "Number::Phone" && building_without_uk() && ($args->[-1] =~ /^\+44/ || $args->[0] =~ /^(GB|UK|GG|JE|IM)$/) ); + my $object = $class->new(@{$args}); + my $obj_class = $object ? blessed($object) : "[undef]"; + ok(defined($object), "$class->new(".join(", ", @{$args}).") returns an object: $obj_class") && ok( # grep is because a number might need to be checked as is_geographic *or* is_fixed_line (grep { $class->new(@{$args})->$_() } @{$methods}), @@ -188,6 +191,7 @@ sub preamble { use lib 't/inc'; use nptestutils; + use Scalar::Util qw(blessed); use Test::More; use Number::Phone; diff --git a/lib/Number/Phone.pm b/lib/Number/Phone.pm index c643c13..856a531 100644 --- a/lib/Number/Phone.pm +++ b/lib/Number/Phone.pm @@ -14,7 +14,7 @@ use Number::Phone::Data; use Number::Phone::StubCountry; # MUST be in format N.NNNN, see https://github.com/DrHyde/perl-modules-Number-Phone/issues/58 -our $VERSION = '3.7002'; +our $VERSION = '3.8004'; my $NOSTUBS = 0; sub import { @@ -48,7 +48,7 @@ sub _find_data_file { if(!$file) { die( - "Couldn't find a UK data file amongst:\n". + "Couldn't find data file '$wanted' amongst:\n". join('', map { " $_\n" } @candidate_files) ); } @@ -183,7 +183,7 @@ bad design decision. Use of those calling conventions was deprecated in version 2.0, released in January 2012, and started to emit warnings. All code to support those calling conventions has now been removed. -Until 2017 we ued KOS for the country code for Kosovo, that has now changed to +Until 2017 we used KOS for the country code for Kosovo, that has now changed to XK. See L. From version 3.4000 to 3.4003 inclusive we accepted any old garbage after @@ -207,7 +207,12 @@ areanames instead of what you used to get. 64 bit ints will be required some time after 2023-06-01. -=head1 COMPATIBILTY WITH libphonenumber +3.8000 is a bit stricter about numbers and countries not matching in the +constructor. This may affect users who specify places like Guernsey but +provide numbers from Jersey or the Isle of Man, all three of which are separate +jurisdictions squatting on random places all over the UK's number plan. + +=head1 COMPATIBILITY WITH libphonenumber libphonenumber is a similar project for other languages, maintained by Google. @@ -233,25 +238,38 @@ want to do this for compatibility or performance. Number::Phone::UK is quite slo sub _new_args { my $class = shift; my($country, $number) = @_; + die("Number::Phone->new(): too many params\n") if(exists($_[2])); + + my $original_country; if(!defined($number)) { # one arg - $number = $country; + $number = $country; } elsif($country =~ /[a-z]/i) { # eg 'UK', '12345' - $number = '+'. - Number::Phone::Country::country_code($country). - $number - unless(index($number, '+'.Number::Phone::Country::country_code($country)) == 0); + $original_country = uc($country); + $number = '+'. + Number::Phone::Country::country_code($country). + $number + unless(index($number, '+'.Number::Phone::Country::country_code($country)) == 0); } else { # (+)NNN - $number = join('', grep { defined } ($country, $number)); + $number = join('', grep { defined } ($country, $number)); } - die("Number::Phone->new(): too many params\n") - if(exists($_[2])); $number =~ s/[^+0-9]//g; - $number = "+$number" unless($number =~ /^\+/); + $country = Number::Phone::Country::phone2country($number) or return; - return $country, $number; + + # special cases where you can legitimately ask for a containing country (eg + # GB) and get back a sub-country (eg GG, which squats upon parts of the GB + # number plan) + if( + ($country eq 'VA' && $original_country eq 'IT') || + ($country =~ /^(IM|GG|JE)$/ && $original_country eq 'GB') + ) { + $original_country = $country; + } + + return ($original_country || $country), $number; } sub new { @@ -260,9 +278,11 @@ sub new { return undef unless($country); if ($number =~ /^\+1/) { $country = "NANP"; - } elsif ($country =~ /^(?:GB|GG|JE|IM)$/) { + } elsif($country eq 'GB') { # for hysterical raisins $country = 'UK'; + } elsif($country =~ /^(GG|JE|IM)$/) { + $country = "UK::$country"; } eval "use Number::Phone::$country"; if($@ || !"Number::Phone::$country"->isa('Number::Phone')) { @@ -270,8 +290,9 @@ sub new { # a test unexpectedly tried to load Number::Phone::UK, argh! die $@ } - # undo the above transformation, it's GB in stub-land - $country = 'GB' if($country eq 'UK'); + # undo the above transformations, for stub-land + if($country eq 'UK') { $country = 'GB' } + if($country =~ /^UK::(..)/) { $country = $1 } return $class->_make_stub_object($number, $country) } return "Number::Phone::$country"->new($number); @@ -295,6 +316,7 @@ sub _make_stub_object { number => $local_number, }, 'Number::Phone::StubCountry'); } + $stub_class->new($number); } @@ -692,8 +714,28 @@ you're talking about, or an object based on Google's libphonenumber data if there's no complete country-specific module available. It is generally assumed that numbers are complete and unambiguous - ie you -can't pass just the local part to the constructor if the number has an area -code. Any subclass's constructor which contravenes this should document it. +can't normally pass just the local part to the constructor if the number has an +area code. Any subclass's constructor which contravenes this should document +it. + +If you call it with two parameters, then the two must match. ie, if you +do this: + + Number::Phone->new("FR", "+441424220001") + +you will get C back because whiel the number is valid, it ain't French. +This usually applies to the case where a single country's number plan contains +other jurisdictions, such as the case of Guernsey, Jersey and the Isle of Man +squatting on the United Kingdom's number plan. For example, this fails, because +the number is from Guernsey, not Jersey: + + Number::Phone->new('JE', '01481256789') + +For backward compatibility and convenience, however, if you ask for an object +representing a number in the "host" country but pass a number for the +"sub-country" then you'll get back a valid object representing the sub-country: + + my $gg_number = Number::Phone->new('GB', '01481256789') =back diff --git a/lib/Number/Phone/Country.pm b/lib/Number/Phone/Country.pm index 59589ca..bfe55ab 100644 --- a/lib/Number/Phone/Country.pm +++ b/lib/Number/Phone/Country.pm @@ -32,43 +32,44 @@ sub phone2country { our %NANP_areas = ( CA => do { # see http://www.cnac.ca/co_codes/co_code_status.htm - # checked on 2020-12-04 - # next check due 2021-06-01 (semi-annually) + # checked on 2021-12-06 + # next check due 2022-06-01 (semi-annually) my $canada = join('|', qw( - 204 226 236 249 250 289 + 204 226 236 249 250 263 289 306 343 354 365 367 368 - 403 416 418 428 431 437 438 450 474 + 403 416 418 428 431 437 438 450 468 474 506 514 519 548 579 581 587 - 604 613 639 647 672 - 705 709 742 778 780 782 + 604 613 639 647 672 683 + 705 709 742 753 778 780 782 807 819 825 867 873 879 902 905 )); # handful of non-geographic country-specific codes ... # see https://en.wikipedia.org/wiki/Area_code_600 - # checked on 2020-06-06 - # next check due 2021-12-01 (semi-annually) + # checked on 2021-12-06 + # next check due 2022-06-01 (semi-annually) $canada = join('|', $canada, 600, 622, 633, 644, 655, 677, 688); }, US => do { - # see https://www.allareacodes.com/area_code_listings_by_state.htm - # and https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#United_States + # see https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#United_States + # and https://www.allareacodes.com/area_code_listings_by_state.htm + # but the latter doesn't contain some overlays that are about to come into service # NB for Hyder, Alaska, it shares three COs with Stewart, BC, and we can't tell which number is in which country, # so those prefixes aren't listed here - # checked on 2020-12-04 - # next check due 2021-06-01 (semi-annually) + # checked on 2021-12-06 + # next check due 2022-06-01 (semi-annually) my $usa = join('|', qw( 205 251 256 334 659 938 907 480 520 602 623 928 327 479 501 870 209 213 279 310 323 341 408 415 424 442 510 530 559 562 619 626 628 650 657 661 669 707 714 747 760 805 818 820 831 840 858 909 916 925 949 951 - 303 719 720 970 + 303 719 720 970 983 203 475 860 959 302 202 771 239 305 321 352 386 407 448 561 656 689 727 754 772 786 813 850 863 904 941 954 - 229 404 470 478 678 706 762 770 912 + 229 404 470 478 678 706 762 770 912 943 808 208 986 217 224 309 312 331 447 464 618 630 708 730 773 779 815 847 872 @@ -112,13 +113,13 @@ our %NANP_areas = ( )); # handful of non-geographic country-specific codes ... # see https://en.wikipedia.org/wiki/Area_code_710 - # checked on 2019-12-11 - # next check due 2021-12-01 (bi-annually) + # checked on 2021-12-06 + # next check due 2023-12-01 (bi-annually) $usa = join('|', $usa, 710); }, # see https://en.wikipedia.org/wiki/North_American_Numbering_Plan#Countries_and_territories - # checked on 2020-12-04 - # next check due 2021-12-01 (annually) + # checked on 2021-12-06 + # next check due 2022-12-01 (annually) AS => '684', # American Samoa AI => '264', # Anguilla AG => '268', # Antigua and Barbude diff --git a/lib/Number/Phone/Lib.pm b/lib/Number/Phone/Lib.pm index bfed0d2..23317b9 100644 --- a/lib/Number/Phone/Lib.pm +++ b/lib/Number/Phone/Lib.pm @@ -13,9 +13,9 @@ sub new { # libphonenumber erroneously treats non-geographic numbers such # as 1-800 numbers as being in the US $country = 'US' if($country eq 'NANP'); - $country = 'GB' if $country eq 'UK'; + $country = 'GB' if($country eq 'UK'); - return $class->_make_stub_object($number, $country) + return $class->_make_stub_object($number, $country); } 1; diff --git a/lib/Number/Phone/NANP.pm b/lib/Number/Phone/NANP.pm index 19d94e4..64ffc12 100644 --- a/lib/Number/Phone/NANP.pm +++ b/lib/Number/Phone/NANP.pm @@ -93,7 +93,7 @@ my $pid = -1; sub _datafh { if(!$datafh || $pid != $$) { my $file = Number::Phone::_find_data_file('Number-Phone-NANP-Data.db'); - open($datafh, '< :raw :bytes', $file) || die("Can't read $file: $!"); + open($datafh, '<:bytes', $file) || die("Can't read $file: $!"); read($datafh, my $header, 8); die("$file isn't the right format\n") unless($header eq 'NANPOP'.chr(0).chr(0)); read($datafh, $WORDLENGTH, 1); diff --git a/lib/Number/Phone/UK.pm b/lib/Number/Phone/UK.pm index b531652..dff4b45 100644 --- a/lib/Number/Phone/UK.pm +++ b/lib/Number/Phone/UK.pm @@ -7,7 +7,7 @@ use Number::Phone::UK::Data; use base 'Number::Phone'; -our $VERSION = '1.70'; +our $VERSION = '1.71'; my $cache = {}; @@ -30,7 +30,9 @@ sub new { $number = '+44'._clean_number($number); if(is_valid($number)) { $number =~ s/^0/+44/; - return bless(\$number, $class->_get_class(_clean_number($number))); + my $target_class = $class->_get_class(_clean_number($number)); + return undef if($class ne $target_class); + return bless(\$number, $target_class); } else { return undef; } } @@ -88,7 +90,8 @@ sub _get_class { if(exists(Number::Phone::UK::Data::db()->{subclass}->{$prefix})) { return $class if(Number::Phone::UK::Data::db()->{subclass}->{$prefix} eq ''); - my $subclass = join('::', $class, Number::Phone::UK::Data::db()->{subclass}->{$prefix}); + my $desired_subclass = Number::Phone::UK::Data::db()->{subclass}->{$prefix}; + my $subclass = "Number::Phone::UK::$desired_subclass"; eval "use $subclass"; return $subclass; } diff --git a/lib/Number/Phone/UK/GG.pm b/lib/Number/Phone/UK/GG.pm index a1da351..131a221 100644 --- a/lib/Number/Phone/UK/GG.pm +++ b/lib/Number/Phone/UK/GG.pm @@ -4,7 +4,7 @@ use strict; use base 'Number::Phone::UK'; -our $VERSION = 1.0; +our $VERSION = 1.1; =head1 NAME @@ -39,7 +39,7 @@ Returns information about the national telecomms regulator. =cut -sub regulator { return 'Office of Utility Regulation, http://www.cicra.gg'; } +sub regulator { return 'Guernsey Competition & Regulatory Authority, https://www.gcra.gg/' } =back diff --git a/lib/Number/Phone/UK/JE.pm b/lib/Number/Phone/UK/JE.pm index f640006..db6b8f8 100644 --- a/lib/Number/Phone/UK/JE.pm +++ b/lib/Number/Phone/UK/JE.pm @@ -4,7 +4,7 @@ use strict; use base 'Number::Phone::UK'; -our $VERSION = 1.0; +our $VERSION = 1.1; =head1 NAME @@ -39,7 +39,7 @@ Returns information about the national telecomms regulator. =cut -sub regulator { return 'Office of Utility Regulation, http://www.cicra.gg'; } +sub regulator { return 'Jersey Competition Regulation Authority, https://www.jcra.je/' } =back diff --git a/t/constructor.t b/t/constructor.t new file mode 100644 index 0000000..50bd7f0 --- /dev/null +++ b/t/constructor.t @@ -0,0 +1,71 @@ +use strict; +use warnings; + +use lib 't/inc'; +use nptestutils; +# *these* tests want to fall back to using stubs instead of dying +BEGIN { shift @INC } +# don't want to pick up a module from a previous installation! +use if building_without_uk, qw(Devel::Hide Number::Phone::UK); + +use Data::Dumper::Concise; +use Test::More; + +use Number::Phone; +use Number::Phone::Lib; + +foreach my $CC (qw(GB GG IM JE)) { + foreach my $class (qw(Number::Phone Number::Phone::Lib)) { + ok(!defined($class->new($CC, '256789')), "$class->new('$CC', '256789') fails (too short)"); + } +} + +foreach my $class (qw(Number::Phone Number::Phone::Lib)) { + my $object = $class->new('+44402609'); + ok(!defined($object), "$class: +44 XXXXXX is invalid, even if XXXXXX is a valid local number in a crown dependency (we ignore nationalPrefixTransformRule in their stubs)"); +} + +foreach my $tuple ( + [qw(GG 01481256789)], + [qw(JE 01534440000)], + [qw(IM 01624756789)], +) { + my($actual_country, $number) = @{$tuple}; + foreach my $country (qw(GG JE IM GB)) { + my $object = Number::Phone::Lib->new($country, $number); + if($country eq 'GB') { + ok($object->isa("Number::Phone::StubCountry::$actual_country"), + "Number::Phone::Lib->new('GB', '$number') returns a Number::Phone::StubCountry::$actual_country") || diag($object); + } elsif($country eq $actual_country) { + ok($object->isa("Number::Phone::StubCountry::$actual_country"), + "Number::Phone::Lib->new('$country', '$number') returns a Number::Phone::StubCountry::$actual_country") || diag($object); + } else { + ok(!defined($object), + "Number::Phone::Lib->new('$country', '$number') fails because $number is actually $actual_country"); + } + + $object = Number::Phone->new($country, $number); + if($country eq 'GB') { + if(building_without_uk) { + ok($object->isa("Number::Phone::StubCountry::$actual_country"), + "Number::Phone->new('GB', '$number') returns a Number::Phone::StubCountry::$actual_country when building --without_uk") || diag($object); + } else { + ok($object->isa("Number::Phone::UK::$actual_country"), + "Number::Phone->new('GB', '$number') returns a Number::Phone::UK::$actual_country") || diag($object); + } + } elsif($country eq $actual_country) { + if(building_without_uk) { + ok($object->isa("Number::Phone::StubCountry::$actual_country"), + "Number::Phone->new('$country', '$number') returns a Number::Phone::StubCountry::$actual_country when building --without_uk") || diag($object); + } else { + ok($object->isa("Number::Phone::UK::$actual_country"), + "Number::Phone->new('$country', '$number') returns a Number::Phone::UK::$actual_country") || diag($object); + } + } else { + ok(!defined($object), + "Number::Phone->new('$country', '$number') fails because $number is actually $actual_country") || diag($object); + } + } +} + +done_testing(); diff --git a/t/inc/common-nanp_and_libphonenumber_tests.pl b/t/inc/common-nanp_and_libphonenumber_tests.pl index 991496b..cf5f24d 100644 --- a/t/inc/common-nanp_and_libphonenumber_tests.pl +++ b/t/inc/common-nanp_and_libphonenumber_tests.pl @@ -127,7 +127,7 @@ skip_if_libphonenumber("Stubs don't support operator", 1, sub { is($CLASS->new('+1 416 392 2489')->operator(), 'Bell Canada', "Canada"); - is($CLASS->new('+1 216 208 0000')->operator(), 'ONVOY LLC - OH', + is($CLASS->new('+1 216 208 0000')->operator(), 'ONVOY, LLC - OH', "Unicode en-dash in some US data converted to hyphen"); my @codes_seen = (); @@ -143,12 +143,12 @@ ['+1 473 230 0000' => 'COLUMBUS COMMUNICATIONS (GRENADA) LIMITED'], ['+1 649 231 0000' => 'CABLE & WIRELESS - TURKS & CAICOS'], # No data yet. - # checked on 2020-12-04 - # next check due 2021-12-01 (annually) until there's data + # checked on 2021-12-06 + # next check due 2022-12-01 (annually) until there's data # at https://localcallingguide.com/xmlprefix.php?npa=658&blocks=1 # ['+1 658 ??? 0000' => '???'], ['+1 664 349 0000' => 'CABLE & WIRELESS - MONTSERRAT'], - ['+1 670 233 0000' => 'MICRONESIAN TELECOMMUNICATIONS CORP.'], + ['+1 670 233 0000' => 'MICRONESIAN TELECOMMUNICATIONS CORPORATION'], ['+1 671 472 7679' => 'TELEGUAM HOLDINGS, LLC'], ['+1 684 248 0000' => 'AST TELECOM, LLC - AS'], ['+1 721 547 0000' => 'ST. MAARTEN TELEPHONE COMPANY, NV'], @@ -174,12 +174,12 @@ "Oh good, the database contains data for all the non-US/CA area codes (except 658, for which no data are yet available)" ); - # checked on 2020-12-04 that these are consolidated ten-thousand blocks - # next check due 2021-12-01 (annually) + # checked on 2021-12-06 that these are consolidated ten-thousand blocks + # next check due 2022-12-01 (annually) # https://localcallingguide.com/xmlprefix.php?npa=630&blocks=1 is($CLASS->new('+1 630 847 0000')->operator(), 'YMAX COMMUNICATIONS CORP. - IL', 'USA, thousands blocks all for same operator, so consolidated into one to save space in database'); - # checked on 2020-12-04 - # next check due 2021-12-01 (annually) + # checked on 2021-12-06 + # next check due 2022-12-01 (annually) # https://localcallingguide.com/xmlprefix.php?npa=242&blocks=1 is($CLASS->new('+1 242 367 0000')->operator(), 'BAHAMAS TELECOMMUNICATIONS CORP.', 'Bahamas, thousands blocks all for same operator, so consolidated into one to save space in database'); @@ -194,16 +194,16 @@ [ 'Bahamas', '+1 242 331 7000', undef ], [ 'Bahamas', '+1 242 331 8000', undef ], [ 'Bahamas', '+1 242 331 9000', undef ], - [ 'USA', '+1 512 373 0000', 'SPRINT SPECTRUM L.P.' ], + [ 'USA', '+1 512 373 0000', 'SPRINT SPECTRUM, L.P.' ], [ 'USA', '+1 512 373 1000', undef ], - [ 'USA', '+1 512 373 2000', 'SPRINT SPECTRUM L.P.', ], + [ 'USA', '+1 512 373 2000', 'SPRINT SPECTRUM, L.P.', ], [ 'USA', '+1 512 373 3000', 'TIME WARNER CBLE INFO SVC (TX) DBA TIME WARNER CBL', ], [ 'USA', '+1 512 373 4000', undef ], - [ 'USA', '+1 512 373 5000', 'SPRINT SPECTRUM L.P.' ], - [ 'USA', '+1 512 373 6000', 'SPRINT SPECTRUM L.P.' ], + [ 'USA', '+1 512 373 5000', 'SPRINT SPECTRUM, L.P.' ], + [ 'USA', '+1 512 373 6000', 'SPRINT SPECTRUM, L.P.' ], [ 'USA', '+1 512 373 7000', undef ], [ 'USA', '+1 512 373 8000', 'TIME WARNER CBLE INFO SVC (TX) DBA TIME WARNER CBL' ], - [ 'USA', '+1 512 373 9000', 'SPRINT SPECTRUM L.P.' ] + [ 'USA', '+1 512 373 9000', 'SPRINT SPECTRUM, L.P.' ] ) { is( $CLASS->new($number->[1])->operator(), diff --git a/t/inc/nptestutils.pm b/t/inc/nptestutils.pm index e2eb37a..41549d7 100644 --- a/t/inc/nptestutils.pm +++ b/t/inc/nptestutils.pm @@ -2,11 +2,19 @@ package nptestutils; use strict; use warnings; + +use Carp; use Exporter qw(import); our @EXPORT = qw(building_without_uk); $SIG{__WARN__} = sub { - die("warning made fatal: ".join('', @_)."\n") + my $warning = join('', @_); + return if( + $warning =~ /Your perl only supports 32 bit ints/ || + $warning =~ /^Devel::Hide/ || + $warning =~ /^Can't locate.*\(hidden\)/ + ); + confess("warning made fatal: ".join('', @_)."\n") }; unshift @INC, sub { @@ -23,7 +31,7 @@ unshift @INC, sub { # we also want this particular failure mode to get reported by N::P and # for it to not fall back to loading a Stub instead. This is to prevent # erroneously writing tests in the future that forget about --without_uk. - die("Building --without_uk but tried to load $wanted_file\n"); + die("Number::Phone built --without_uk but tried to load $wanted_file\n"); }; sub building_without_uk { !-e 'blib/lib/Number/Phone/UK.pm' } diff --git a/t/number-phone-country-prefix.t b/t/number-phone-country-prefix.t index faea489..ded0322 100644 --- a/t/number-phone-country-prefix.t +++ b/t/number-phone-country-prefix.t @@ -265,7 +265,7 @@ TD:235:00: TF:596:00:0 TG:228:00: TH:66:001:0 -TJ:992:810:8 +TJ:992:810: TK:690:00: TL:670:00: TM:993:810:8 diff --git a/t/number-phone-country.t b/t/number-phone-country.t index 065c29a..1cd7df5 100644 --- a/t/number-phone-country.t +++ b/t/number-phone-country.t @@ -253,6 +253,7 @@ is(phone2country('+67210123'), 'AQ', '+67210 is AQ'); is(phone2country('+67211123'), 'AQ', '+67211 is AQ'); is(phone2country('+67212123'), 'AQ', '+67212 is AQ'); is(phone2country('+67213123'), 'AQ', '+67213 is AQ'); +is(phone2country('+882345'), 'AQ', '+67213 is AQ'); # Global Networks Switzerland is(phone2country('+6723123'), 'NF', '+6723 is NF'); is(phone2country('+673123'), 'BN', '+673 is BN'); is(phone2country('+674123'), 'NR', '+674 is NR'); diff --git a/t/unicode.t b/t/unicode.t index 3e3af00..f26e094 100644 --- a/t/unicode.t +++ b/t/unicode.t @@ -1,21 +1,29 @@ use strict; use warnings; +use utf8; use lib 't/inc'; use nptestutils; -use Test::More; +use Devel::Hide qw(Number::Phone::DE Number::Phone::JP); -use Number::Phone; +# So we can see any diagnostics from is() without moaning about wide chars; +# we may still get such moans from machines with ISO-8859 terminals if the +# tests fail there. Must be before Test::More is loaded +BEGIN { binmode STDOUT, ":utf8"; } -eval 'use Test::utf8'; +use Test::More; -SKIP: { - skip("Test::utf8 not available", 1) if($@); +use Number::Phone; - is_flagged_utf8( - Number::Phone->new("+49 906 1234567")->areaname(), - "Donauwörth area name isflagged as UTF-8" - ); -}; +is( + Number::Phone->new("+49 906 1234567")->areaname(), + 'Donauwörth', + "German area name with rock dots is decoded to Unicode characters" +); +is( + Number::Phone->new("+81 982 22-7006")->areaname('ja'), + '延岡', + "Japanese area name is decoded to Unicode characters too", +); done_testing(); diff --git a/t/weird_little_islands.t b/t/weird_little_islands.t index d6743b9..a914790 100644 --- a/t/weird_little_islands.t +++ b/t/weird_little_islands.t @@ -14,13 +14,13 @@ my $data = { mobile => '+44 7700 300000', # used specifically because there's a special case for 7700 900 geographic => '+44 1534 440000', operator => qr/^(JT|Sure) \(Jersey\) Limited$/, - regulator => 'Office of Utility Regulation, http://www.cicra.gg' + regulator => 'Jersey Competition Regulation Authority, https://www.jcra.je/', }, GG => { mobile => '+44 7781 000000', geographic => '+44 1481 200000', operator => 'Sure (Guernsey) Limited', - regulator => 'Office of Utility Regulation, http://www.cicra.gg' + regulator => 'Guernsey Competition & Regulatory Authority, https://www.gcra.gg/' }, IM => { mobile => ['+44 7624 000000', '+44 7457 600000'],