Permalink
Browse files

Bugfix for Number::Phone->new('CC', '123456789'), bug reported by mst…

…evens
  • Loading branch information...
1 parent b10469c commit 97c3de35f9a320061516299fbe33d10518304a92 @DrHyde DrHyde committed Jul 2, 2010
Showing with 44 additions and 4 deletions.
  1. +3 −0 CHANGELOG
  2. +1 −0 MANIFEST
  3. +17 −4 lib/Number/Phone.pm
  4. +23 −0 t/901_bugfix_N-P-New-CC-number.t
View
3 CHANGELOG
@@ -1,3 +1,6 @@
+2010-07-02 1.7100 Bugfix for N::P->new('CC', '12345');
+ New UK allocations
+
2010-02-17 1.7004 New UK allocations;
UK geographic numbers are no longer assumed to
be fixed lines - damn those VoIP providers!
View
1 MANIFEST
@@ -50,3 +50,4 @@ lib/Number/Phone/UK/DBM/Deep.pm
t/30_find-right-subclass.t
t/54_number-phone-country-prefix.t
t/900_bugfix-rt48581.t
+t/901_bugfix_N-P-New-CC-number.t
View
21 lib/Number/Phone.pm
@@ -6,7 +6,7 @@ use Scalar::Util 'blessed';
use Number::Phone::Country qw(noexport uk);
-our $VERSION = 1.7004;
+our $VERSION = 1.7100;
my @is_methods = qw(
is_valid is_allocated is_in_use
@@ -89,6 +89,8 @@ and to magically use the right subclass ...
$daves_phone = Number::Phone->new('+442087712924');
$daves_other_phone = Number::Phone->new('+44 7979 866 975');
+ # alternatively Number::Phone->new('+44', '7979 866 975');
+ # or Number::Phone->new('UK', '07979 866 975');
if($daves_phone->is_mobile()) {
send_rude_SMS();
@@ -103,15 +105,26 @@ no supporting module is available, the constructor will return undef.
sub new {
my $class = shift;
- my $number = join('', grep { defined } @_[0, 1]);
+ my($country, $number) = @_;
+
+ if(!defined($number)) {
+ $number = $country;
+ } elsif($country =~ /[a-z]/i) { # eg 'UK', '12345'
+ $number = '+'.
+ Number::Phone::Country::country_code($country).
+ $number;
+ } else {
+ $number = join('', grep { defined } ($country, $number));
+ }
+
die("Need to specify a number for ".__PACKAGE__."->new()\n")
unless($number);
die("Number::Phone->new(): too many params\n")
if(exists($_[2]));
$number =~ s/\D//g;
$number = "+$number" unless($number =~ /^\+/);
- my $country = Number::Phone::Country::phone2country($number);
+ $country = Number::Phone::Country::phone2country($number);
return undef unless($country);
$country = "NANP" if($number =~ /^\+1/);
eval "use Number::Phone::$country";
@@ -375,6 +388,6 @@ perl itself.
David Cantrell E<lt>david@cantrell.org.ukE<gt>
-Copyright 2004 - 2009
+Copyright 2004 - 2010
=cut
View
23 t/901_bugfix_N-P-New-CC-number.t
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+my $loaded;
+
+use strict;
+
+use Number::Phone;
+
+BEGIN { $| = 1; print "1..5\n"; }
+
+my $test = 0;
+
+print 'not ' unless((Number::Phone->new('UK', '07970866975')));
+print 'ok '.(++$test)." list N::P->new('CC', '012345')\n";
+print 'not ' unless((Number::Phone->new('+44', '7970866975')));
+print 'ok '.(++$test)." list N::P->new('+NN', '12345')\n";
+print 'not ' unless((Number::Phone->new('+447970866975')));
+print 'ok '.(++$test)." list N::P->new('+NN12345')\n";
+
+print 'not ' unless((Number::Phone->new('UK', '7970866975'))); # not strictly correct
+print 'ok '.(++$test)." list N::P->new('CC', '12345')\n";
+print 'not ' unless((Number::Phone->new('+44', '07970866975'))); # not strictly correct
+print 'ok '.(++$test)." list N::P->new('+NN', '012345')\n";

0 comments on commit 97c3de3

Please sign in to comment.