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   29 use strict;
  9         10  
  9         185  
3 9     9   29 use warnings;
  9         8  
  9         154  
4              
5 9     9   26 use String::Normal::Config::AreaCodes;
  9         9  
  9         1431  
6              
7             our $codes;
8              
9             sub transform {
10 2     2 1 3 my ($self,$value) = @_;
11              
12             # Replace phone letters with numbers and remove non-digits (credit Ray Toal)
13 2         4 $value =~ tr/a-z/22233344455566677778889999/;
14 2         8 $value =~ s/\D//g;
15              
16             # remove any leading 1 from 11 digit number
17 2 50       6 $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         4 my $areacode_first = substr $value, 0, 1;
25 2 50       5 if ($areacode_first < 2) {
26 0         0 die "invalid area code";
27             }
28              
29 2         8 return $value;
30             }
31              
32             sub new {
33 1     1 1 1 my $self = shift;
34 1         4 $codes = String::Normal::Config::AreaCodes::_data( @_ );
35 1         4 return bless {@_}, $self;
36             }
37              
38             1;
39              
40             __END__