Open lejeunerenard opened 9 years ago
You mean that you want to be able to do this ...
my $number = Number::Phone->new('011447979866975')
instead of ...
my $number = Number::Phone->new('+447979866975')
?
I don't like this. The various parsers scattered throughout the code are already complex and confusing, and I don't want to add more complexity, confusion, and possibility of inconsistency.
I think it would be better to have a class method on Number::Phone that you would invoke in a sub-class something like this ...
my $e123 = Number::Phone::NANP->dialstring_to_e123('01144...')
whose results you could pass to the constructor. Of course, you have to know where you're dialling from so that you can pick the right subclass, but I think that's a reasonable restriction. And it beats a partial implementation that will only work for some countries, and (if we're not careful) only some variations of the multitudinous constructors.
I agree 100%. Leaving it up to the developer to figure out where the number is coming from is reasonable, as long as the class method is named the same for all sub-classes.
Would it make sense to create a dialstring_to_e123()
on the parent class Number::Phone
that simply dies with an error like dialstring_to_e123() not implemented for __PACKAGE__
? Similar to https://github.com/DrHyde/perl-modules-Number-Phone/blob/master/lib/Number/Phone.pm#L189. Or would it be better to infer the country with Number::Phone::Country::phone2country
?
I can take a stab at making a PR for at least the Number::Phone::NANP
sub-class if you'd like. Just let me know.
I suspect that it's best to put all the code in the Number::Phone base class, but only allow it to be invoked on a subclass. That way, the code only has to be written once for all countries. It should be pretty generic, as the country_code
method will give you enough information to look up the idd code (using Number::Phone::Country::idd_code
) that you need to strip off.
@lejeunerenard FYI I've merged @mimeraynham's PR referenced above.
Currently when using the international prefixes
00
(ITU-T) or011
(NANP), validation fails.I propose one of two options:
00
&011
) when creating a new number.I recommend and would be willing to implement No 1.
References:
ITU-T International prefix definition ( Section 12 on page 14 in English version ) NANP International prefix definition via Wikipedia