Number::Phone::Formatters(3pm)

Number::Phone::Formatters3pm

How to write custom formatters

Overview

How to write custom formatters for phone numbers.

Naming

Formatters are modules that live in the "Number::Phone::Formatter::*" namespace. Users only need to type the last bit of the name, without the leading "Number::Phone::Formatter::", when calling the "format_using" method of Number::Phone.

The 'E123' formatter name is reserved and implemented by Number::Phone subclasses in their "format()" methods.

The 'FishAndChips' formatter name is reserved because I needed something guaranteed to not exist so I could test that it failed correctly.

Methods

There is one compulsory method, "format" that you must write. It will be called as a class method, with a number in E.123 international format as its first argument, looking something like '+CC NNN NNN NNN', and a Number::Phone object as its second argument. The gory details of what E.123 looks like are at <http://www.itu.int/rec/T-REC-E.123/en> but in summary, you'll get a string consisting of:

a plus sign
a 1, 2 or 3 digit country code
whitespace
a mixture of digits and whitespace

You should return a string.

Examples

See Number::Phone::Formatter::Raw for an example that uses the string argument, and Number::Phone::Formatter::NationallyPreferredIntl for one that uses the object.

Releases

3 releases since Debian 9 (Stretch); the text changed 2 times.

  1. 9
  2. 10
  3. 11

From libnumber-phone-perl 3.6006-1 in Debian 11 (Bullseye). Parsed by carta from the page's man source.