File Coverage

blib/lib/String/Normal/Type/Phone.pm
Criterion Covered Total %
statement 20 22 90.9
branch 3 6 50.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 30 35 85.7


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