| 1 | package String::Normal::Type::Phone; | ||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 9 | ▶ | use String::Normal::Config::AreaCodes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 9 | our $codes; | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | sub transform { | ||||||||
|
Subroutine
transform: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||
| 10 | 2 | my ($self,$value) = @_; | |||||||||
| 11 | |||||||||||
| 12 | # Replace phone letters with numbers and remove non-digits (credit Ray Toal) | ||||||||||
| 13 | 2 | $value =~ tr/a-z/22233344455566677778889999/; | |||||||||
| 14 | 2 | $value =~ s/\D//g; | |||||||||
| 15 | |||||||||||
| 16 | # remove any leading 1 from 11 digit number | ||||||||||
| 17 | 2 | ▶ | $value =~ /^1\d{10}$/ and substr( $value, 0, 1 ) = ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | if (length($value) != 10) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | die "invalid length"; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | # validate area code (first digit cannot be 1 or 0) | ||||||||||
| 24 | 2 | my $areacode_first = substr $value, 0, 1; | |||||||||
| 25 | 2 | ▶ | if ($areacode_first < 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | die "invalid area code"; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 2 | return $value; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 1 | my $self = shift; | |||||||||
| 34 | 1 | $codes = String::Normal::Config::AreaCodes::_data( @_ ); | |||||||||
| 35 | 1 | return bless {@_}, $self; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 9 | 1; | |||||||||
| 39 | |||||||||||
| 40 | __END__ | ||||||||||