Skip to content

Commit

Permalink
notes on coverage; telco_format should always be fully populated; tid…
Browse files Browse the repository at this point in the history
…y up UK format function and get rid of an unused path
  • Loading branch information
DrHyde committed Oct 19, 2016
1 parent a084df7 commit 3b78444
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
11 changes: 11 additions & 0 deletions NOTES
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
National numbering plans:
http://www.itu.int/ITU-T/inr/nnp/index.html

Coverage:
stubs at 100% except:
JE: mysterious!
MF: because of overlapping number ranges with GP and BL
VA: because it's part of Italy as far as libphonenumber is concerned
NANP at 100% except:
NANP.pm: appears to be some oddity around eval "use ..."

Number::Phone needs branch/cond coverage improving
N::P::Country needs branch improvements
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
better OFCOM parser
clean up N::P::UK->format()
more systematic UK tests
details for NANP-ish countries
details for non-geo NANP numbers
Expand Down
31 changes: 15 additions & 16 deletions lib/Number/Phone/UK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ sub is_valid {
my($telco_and_length) = map { $Number::Phone::UK::Data::db->{telco_and_length}->{$_} } grep { $Number::Phone::UK::Data::db->{telco_and_length}->{$_} } @prefixes;
$cache->{$number}->{operator} = $Number::Phone::UK::Data::db->{telco_format}->{$telco_and_length}->{telco};
$cache->{$number}->{format} = $Number::Phone::UK::Data::db->{telco_format}->{$telco_and_length}->{format};
# uncoverable condition left
if(defined($cache->{$number}->{format}) && $cache->{$number}->{format} =~ /\+/) {

if($cache->{$number}->{format} =~ /\+/) {
my($arealength, $subscriberlength) = split(/\+/, $cache->{$number}->{format});
# for hateful mixed thing
my @subscriberlengths = ($subscriberlength =~ m{/}) ? split(/\//, $subscriberlength) : ($subscriberlength);
Expand Down Expand Up @@ -354,25 +354,24 @@ number.
=item format
Return a sanely formatted version of the number, complete with IDD code, eg
for the UK number (0208) 771-2924 it would return +44 20 87712924.
for the UK number (0208) 771-2924 it would return +44 20 8771 2924.
=cut

sub format {
my $self = shift;
return (
# if there's an areacode ...
$self->areacode() ? ('+'.country_code().' '.$self->areacode().' '.(
length($self->subscriber()) == 7 ? substr($self->subscriber(), 0, 3).' '.substr($self->subscriber(), 3) :
length($self->subscriber()) == 8 ? substr($self->subscriber(), 0, 4).' '.substr($self->subscriber(), 4) :
$self->subscriber() )) :
# if not allocated ...
!$self->is_allocated() ? '+'.country_code().' '.( ${$self} =~ /^\+44/ ? substr(${$self}, 3) : substr(${$self}, 1)) :
# if there's a subscriber ...
$self->subscriber() ? '+'.country_code().' '.$self->subscriber :
# otherwise ...
${$self}
);
my $r = ${$self};
if($self->areacode()) { # if there's an areacode ...
$r = '+'.country_code().' '.$self->areacode().' ';
if( length($self->subscriber()) == 7) { $r .= substr($self->subscriber(), 0, 3).' '.substr($self->subscriber(), 3) }
elsif(length($self->subscriber()) == 8) { $r .= substr($self->subscriber(), 0, 4).' '.substr($self->subscriber(), 4) }
else { $r .= $self->subscriber() }
} elsif(!$self->is_allocated()) { # if not allocated ...
$r = '+'.country_code().' '.substr(${$self}, 3)
} elsif($self->subscriber()) { # if there's a subscriber ...
$r = '+'.country_code().' '.$self->subscriber
}
return $r;
}

=item intra_country_dial_to
Expand Down

0 comments on commit 3b78444

Please sign in to comment.