Skip to content
Browse files

Bugfix, see RT 48581

  • Loading branch information...
1 parent 9ff0d32 commit 39960a9f548e25d88a3f30b7a12a9f6b2bd18651 @DrHyde DrHyde committed Oct 18, 2009
Showing with 20 additions and 15 deletions.
  1. +4 −15 lib/Number/Phone.pm
  2. +16 −0 t/900_bugfix-rt48581.t
View
19 lib/Number/Phone.pm
@@ -99,28 +99,17 @@ so the appropriate country-specific module is loaded if available.
If you pass in a bogus country code or one for a country for which
no supporting module is available, the constructor will return undef.
-=head1 IMPORTANT NOTE WHAT YOU SHOULD READ
-
-All previous versions had a dependency on the excellent DBM::Deep module.
-Unfortunately its file format changed when it hit version 1.0. Therefore
-this release has an old version of DBM::Deep bundled with it, which you
-may use in parallel with the new version.
-
=cut
sub new {
- my($class, $number) = @_;
+ my $class = shift;
+ my $number = join('', grep { defined } @_[0, 1]);
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;
- # foreach my $retard (
- # map { substr($number, 0, $_) }
- # reverse 1 .. length($number)
- # ) {
- # return $subclasses{$retard}->new("+$number") if($subclasses{$retard});
- # }
-
$number = "+$number" unless($number =~ /^\+/);
my $country = Number::Phone::Country::phone2country($number);
return undef unless($country);
View
16 t/900_bugfix-rt48581.t
@@ -0,0 +1,16 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 3;
+
+use Number::Phone;
+
+my $phone = Number::Phone->new(44, '02087712924');
+
+ok($phone->isa('Number::Phone::UK'), "N::P->new(CC, 'nnnn') returns N::P::CC object");
+
+ok($phone->format() eq "+44 20 87712924", "and it's got the right data");
+
+eval { Number::Phone->new(44, '02087712924', 'apples!') };
+ok($@ =~ /too many params/, "dies OK on too many params");

0 comments on commit 39960a9

Please sign in to comment.
Something went wrong with that request. Please try again.