Permalink
Browse files

N::P::UK parser (and data builder) fixed for 01768 88 mixed length st…

…upidity
  • Loading branch information...
DrHyde committed Jul 19, 2011
1 parent 1435f2b commit b50becafef6f4f3d1f064eafecc5a01ad13bb4da
Showing with 24 additions and 8 deletions.
  1. +3 −1 CHANGELOG
  2. +1 −1 build-data.realwork
  3. +3 −1 lib/Number/Phone/UK.pm
  4. BIN lib/Number/Phone/UK/Data.pm
  5. +17 −5 t/01_uk_data.t
View
@@ -1,4 +1,6 @@
-XXXX-XX-XX 1.8003 UK parser made a teensy bit more robust;
+2011-07-19 1.8003 UK parser made a teensy bit more robust;
+ UK parser bugfixed for 01768 88 mixed length stupidity
+ New UK allocations
2011-07-08 1.8002 New UK allocations;
Numerous small changes in Number::Phone::Country
View
@@ -234,7 +234,7 @@ foreach my $datum (@telco_length_data) {
warn "Empty format: $format (r: $retard; t: $telco)\n"
if($retard !~ /^[789]/);
} elsif($format eq 'Mixed 4+5 & 4+6') {
- $format = '4+5 mixed';
+ $format = '4+5/6';
} elsif(
$format ne '2+8' &&
$format ne '2+8' &&
View
@@ -103,6 +103,8 @@ sub is_valid {
$cache->{$number}->{format} = $Number::Phone::UK::Data::db->{telco_format}->{$telco_and_length}->{format};
if(defined($cache->{$number}->{format}) && $cache->{$number}->{format} =~ /\+/) {
my($arealength, $subscriberlength) = split(/\+/, $cache->{$number}->{format});
+ # for hateful mixed thing
+ my @subscriberlengths = ($subscriberlength =~ m{/}) ? split(/\//, $subscriberlength) : ($subscriberlength);
$subscriberlength =~ s/^(\d+).*/$1/; # for hateful mixed thing
$cache->{$number}->{areacode} = substr($parsed_number, 0, $arealength);
$cache->{$number}->{subscriber} = substr($parsed_number, $arealength);
@@ -111,7 +113,7 @@ sub is_valid {
$Number::Phone::UK::Data::db->{areanames}->{$_}
} grep { $Number::Phone::UK::Data::db->{areanames}->{$_} } @retards
)[0];
- if(length($cache->{$number}->{subscriber}) != $subscriberlength && $cache->{$number}->{format} !~ /mixed/i) {
+ if(!grep { length($cache->{$number}->{subscriber}) == $_ } @subscriberlengths) {
# number wrong length!
$cache->{$number} = undef;
return 0;
View
Binary file not shown.
View
@@ -6,7 +6,7 @@ use strict;
use Number::Phone::UK;
-BEGIN { $| = 1; print "1..68\n"; }
+BEGIN { $| = 1; print "1..73\n"; }
my $test = 0;
@@ -151,12 +151,24 @@ print 'ok '.(++$test)." 03 numbers are formatted right\n";
print 'not ' unless(Number::Phone->new('+44169772200')->format() eq
'+44 16977 2200');
print 'ok '.(++$test)." 5+4 format works\n";
-print 'not ' unless(Number::Phone->new('+44176888000')->format() eq
- '+44 1768 88000');
+
+# 01768 88 is "Mixed 4+5 & 4+6". I wish someone would just set the village on fire.
+print 'not ' unless(Number::Phone->new('+44 1768 88 000')->format() eq '+44 1768 88000'); # 4+5
+print 'ok '.(++$test)." 4+5 (mixed) format works\n";
+print 'not ' unless(Number::Phone->new('+44 1768 88 100')->format() eq '+44 1768 88100');
print 'ok '.(++$test)." 4+5 (mixed) format works\n";
-print 'not ' unless(Number::Phone->new('+441768881000')->format() eq
- '+44 1768 881000');
+
+print 'not ' unless(Number::Phone->new('+44 1768 88 0000')->format() eq '+44 1768 880000'); # 4+6
print 'ok '.(++$test)." 4+6 (mixed) format works\n";
+print 'not ' unless(Number::Phone->new('+44 1768 88 1000')->format() eq '+44 1768 881000');
+print 'ok '.(++$test)." 4+6 (mixed) format works\n";
+
+print 'not ' if(Number::Phone->new('+44 1768 88 0')); # 4+3
+print 'ok '.(++$test)." 4+3 in that range correctly fails\n";
+print 'not ' if(Number::Phone->new('+44 1768 88 00')); # 4+4
+print 'ok '.(++$test)." 4+4 in that range correctly fails\n";
+print 'not ' if(Number::Phone->new('+44 1768 88 00000')); # 4+7
+print 'ok '.(++$test)." 4+7 in that range correctly fails\n";
$number = Number::Phone->new('+447400000000');
print 'not ' unless($number->is_mobile());

0 comments on commit b50beca

Please sign in to comment.