Normal/Type/Phone.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 86.4% 32 / 37 CC 4 SCAR 10.1
CC
4
Cov
83%
transform
4.5
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« Normal/Type/Zip.pm ↑ Summary Normal/Config/BusinessCompress.pm »
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
BranchTrueFalseTotal
$value =~ /^1\d{10}$/ and substr($value, 0, 1) = "" 0 2 2
18  
19 2 ▶ if (length($value) != 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value != 10) 0 2 2
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
BranchTrueFalseTotal
if ($areacode_first < 2) 0 2 2
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__
« Normal/Type/Zip.pm ↑ Summary Normal/Config/BusinessCompress.pm »