Skip to content

Commit

Permalink
bugfix so we can say Number::Phone->new('GMSS::Iridium' => 'numbers')…
Browse files Browse the repository at this point in the history
… etc
  • Loading branch information
DrHyde committed Jan 13, 2023
1 parent a93f3a9 commit 80018e5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ t/constructor.t
lib/Number/Phone/StubCountry/GMSS/Globalstar.pm
lib/Number/Phone/StubCountry/GMSS/ICO.pm
lib/Number/Phone/StubCountry/GMSS/Iridium.pm
lib/Number/Phone/StubCountry/InternationalNetworks882/GarudaMobile.pm
lib/Number/Phone/StubCountry/InternationalNetworks882/Telespazio.pm
lib/Number/Phone/StubCountry/InternationalNetworks882/Thuraya.pm
lib/Number/Phone/StubCountry/InternationalNetworks883/MTTGlobalNetworks.pm
Expand Down
27 changes: 24 additions & 3 deletions build-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@
# warn("$ISO_country_code number +$IDD_country_code $number in libphonenumber's example data is wrong\n");
next NUMBER;
}
my $constructor_args = [map { "'$_'" } @{$test_tuple}];
my $constructor_args = [@{$test_tuple}];
my @classes = $IDD_country_code eq '44' ? qw(Number::Phone Number::Phone::Lib) :
$IDD_country_code eq '1' ? qw(Number::Phone Number::Phone::Lib) :
$IDD_country_code =~ /$non_geo_IDD_codes_regex/
? qw(Number::Phone Number::Phone::Lib) :
qw(Number::Phone::Lib);

if(!ref($test_method)) { $test_method = [$test_method] }
my $test_methods = [map { "'$_'" } @{$test_method}];
my $test_methods = [@{$test_method}];

foreach my $class (@classes) {
push @tests, {
Expand All @@ -149,9 +149,30 @@
}
}

foreach my $class (qw(Number::Phone Number::Phone::Lib)) {
foreach my $test (
[qw(GMSS::Iridium 612345678 +881612345678)],
[qw(GMSS::ICO 012345678 +881012345678)],
[qw(GMSS::Globalstar 812345678 +881812345678)],
[qw(InternationalNetworks882::Telespazio 13201234 +88213201234)],
[qw(InternationalNetworks882::Thuraya 1610100 +8821610100 )],
[qw(InternationalNetworks883::MTTGlobalNetworks 14000000 +88314000000)],
) {
push @tests, {
class => $class,
args => [$test->[0], $test->[$_]],
methods => [
$test->[0] =~ /^GMSS/ ? 'is_mobile' :
$test->[0] =~ /^InternationalNetworks88[23]/ ? 'is_ipphone' :
()
]
} foreach(1, 2);
}
}

print $testfh 'foreach my $test (';
foreach my $test (@tests) {
print $testfh "{ class => '".$test->{class}."', args => [".join(',',@{$test->{args}})."], methods => [".join(',',@{$test->{methods}})."] },\n";
print $testfh "{ class => '".$test->{class}."', args => [".join(',', map { "'$_'" } @{$test->{args}})."], methods => [".join(',', map { "'$_'" } @{$test->{methods}})."] },\n";
}
print $testfh ') {
my($class, $args, $methods) = map { $test->{$_} } qw(class args methods);
Expand Down
1 change: 0 additions & 1 deletion buildtools/Number/Phone/BuildHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ sub known_non_country_codes {
882 => 'InternationalNetworks882', # many allocations not listed as I don't know if they're diallable, see wtng.info
88213 => 'InternationalNetworks882::Telespazio', # Sat-phone
88216 => 'InternationalNetworks882::Thuraya', # Sat-phone
88220 => 'InternationalNetworks882::GarudaMobile', # Sat-phone
88234 => 'AQ', # Antarctica, via Global Networks Switzerland, http://wtng.info/wtng-spe.html#Networks
883 => 'InternationalNetworks883',
883130 => 'InternationalNetworks883::Mobistar',
Expand Down
17 changes: 13 additions & 4 deletions lib/Number/Phone.pm
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ sub _new_args {
die("Number::Phone->new(): too many params\n") if(exists($_[2]));

my $original_country;
$original_country = $country if($country =~ /::/);

if(!defined($number)) { # one arg
$number = $country;
Expand All @@ -272,10 +273,18 @@ sub _new_args {
# ('InternationalNetworks882', ...)
# we accept lower-case ISO codes
$original_country = uc($country) if($country =~ /^[a-z]{2}$/i);
$number = '+'.
Number::Phone::Country::country_code($country).
$number
unless(index($number, '+'.Number::Phone::Country::country_code($country)) == 0);
if($country =~ /^GMSS::[a-zA-Z]+$/) {
if($number !~ /^\+881/) {
$number = "+881$number";
}
} elsif($country =~ /^InternationalNetworks(88[23])::[a-zA-Z]+$/) {
my $idd = $1;
if($number !~ /^\+$idd/) {
$number = "+$idd$number";
}
} elsif(index($number, '+'.Number::Phone::Country::country_code($country)) != 0) {
$number = '+'.Number::Phone::Country::country_code($country).$number;
}
} else { # (+)NNN
$number = join('', grep { defined } ($country, $number));
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion t/inc/common-stub_and_libphonenumber_tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
isa_ok($international883_mtt, "Number::Phone::StubCountry");
isa_ok($international883_mtt, "Number::Phone::StubCountry::InternationalNetworks883");
isa_ok($international883_mtt, "Number::Phone::StubCountry::InternationalNetworks883::MTTGlobalNetworks");
is($international883_mtt->country(), 'MTTGlobalNetworks', '$CLASS->new("+88312000000")->country()');
is($international883_mtt->country(), 'MTTGlobalNetworks', '$CLASS->new("+88314000000")->country()');

my $fo = $CLASS->new('+298 303030'); # Faroes Telecom
is($fo->country_code(), 298, "$CLASS->new('+298 303030')->country_code()");
Expand Down

0 comments on commit 80018e5

Please sign in to comment.