Closed mschout closed 8 years ago
Just to comment on this, I need a way to get the raw parsed phone number out of Number::Phone objects in order to do my own formatting into E.164 format as required by EPP (e.g.: +1.2145555555). Number::Phone doesn't seem to expose a method to get the raw number (2145555555) in this case. Some subclasses like NANP provide areacode() and subscriber() methods, but StubCountry objects do not, so those methods are really not an option. So I implemented number() to get at the raw number instead. Let me know if any of this is unclear or if I just completely missed how to get the raw number.
E.164 doesn't actually define the format, it merely defines what all the various sub-structures mean.
The format() method will give you the number in E.123 format, which is +CC then whitespace, then the number with country-specific spacing. The best implementation, which would also work for any Number::Phone::CC modules that third parties upload to the CPAN (eg Number::Phone::IE), would be to implement this as a wrapper around format(), in the superclass. Something like ...
sub raw_number {
my $fmted = shift()->format(shift());
$fmted =~ s/.*?\s//;
$fmted =~ s/\s//g;
return $fmted
}
or even
sub format_epp {
my $fmted = shift()->format(shift());
$fmted =~ s/\s/./;
$fmted =~ s/\s//g;
return $fmted
}
All of which is a long way of saying "thanks, good idea, I'll implement it differently" :-)
Hmm, make that format_rfc5733
, not format_epp
.
I agree with you that EPP (RFC 5733) formatting doesn't belong in Number::Phone itself. I hadn't considered a wrapper around format() that "undoes" the formatting. Anyway, thanks for the update. The raw_number() method you provided is basically what I needed that is missing. Thanks for your hard work on this great module!
I've pushed a raw_number()
method to master. It'll be in the next scheduled release, during the first weekend of March.
oh, and i mostly nicked your tests out of this PR. thanks!
I'm renaming raw_number
to format_using('Raw')
. That way, anyone can write formatters without them having to be bundled with Number::Phone.
Great, I can write an EPP formatter :).
If you upload it to the CPAN (and I encourage you to do so!) then you'll need to wait until I upload a version of N::P that supports this (some time in the next few days) and declare a dependency on at least version 3.0015.
3.1 should hit a CPAN mirror near you any hour now.
Great thanks!
This method returns the raw unformatted phone number, minus the country code. This is the same as $self->{number} for a StubCountry object, or, the value of $$self with the country code removed for UK/NANP numbers.