DrHyde / perl-modules-Number-Phone

Number::Phone and friends
24 stars 32 forks source link

add number method #56

Closed mschout closed 8 years ago

mschout commented 8 years ago

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.

mschout commented 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.

DrHyde commented 8 years ago

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" :-)

DrHyde commented 8 years ago

Hmm, make that format_rfc5733, not format_epp.

mschout commented 8 years ago

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!

DrHyde commented 8 years ago

I've pushed a raw_number() method to master. It'll be in the next scheduled release, during the first weekend of March.

DrHyde commented 8 years ago

oh, and i mostly nicked your tests out of this PR. thanks!

DrHyde commented 8 years ago

I'm renaming raw_number to format_using('Raw'). That way, anyone can write formatters without them having to be bundled with Number::Phone.

mschout commented 8 years ago

Great, I can write an EPP formatter :).

DrHyde commented 8 years ago

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.

DrHyde commented 8 years ago

3.1 should hit a CPAN mirror near you any hour now.

mschout commented 8 years ago

Great thanks!