blib/lib/Data/Validate/WithYAML/Plugin/Phone.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 12 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 61 / 61 CC 8 SCAR 12.7
CC
8
Cov
100%
check
6.0
__ANON__
3.0
BEGIN
1.0
CRAP 3.6
↑ Summary
1 package Data::Validate::WithYAML::Plugin::Phone;
2  
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Plugin to check Phone numbers (basic check)
11  
12 6 our $VERSION = '0.06';
13  
14  
15 61 ▶sub check {
Subroutine check: called CC=6 SCAR=17.9
Pod documented
16 61 my ($class, $value, $config) = @_;
17
18 61 ▶ croak "no value to check" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 60 61
19  
20 60 ▶ if ( $config && $config->{country} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config and $config->{"country"}) 24 36 60
Condition100%3/3
$config and $config->{"country"}
!ll&&!rl&&r
181824
MC/DC100%2/2
$config and $config->{"country"}
$config $config->{"country"}
Truth table100%3/3
A and B
A= $configB= $config->{"country"}
ABresult
0X0
100
111
21 24 my $country = $config->{country};
22 24 my $return = 0;
23 24 my $number;
24 my $error;
25  
26 24 require 'Number/Phone.pm';
27  
28 24 ▶ try {
Subroutine __ANON__: called CC=3 SCAR=11.0
29 24 $number = Number::Phone->new( $country, $value );
30  
31 10 ▶ return if !blessed $number;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($number) 1 9 10
32  
33 9 ▶ $error = 'No support for ' . $country if $number->isa('Number::Phone::StubCountry');
Branch: 1 branch
BranchTrueFalseTotal
if $number->isa("Number::Phone::StubCountry") 1 8 9
34  
35 9 $return = 1;
36 24 };
37  
38 24 ▶ croak $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 1 23 24
39  
40 23 return $return;
41 }
42
43 36 my $return = 0;
44 36 $value =~ s/\s//g;
45 36 ▶ if( $value =~ m{\A (?: \+ | 00? ) [1-9]{2,6} \s*? [/-]? \s*? [0-9]{4,12} \z}x ){
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ m[\A (?: \+ | 00? ) [1-9]{2,6} \s*? [/-]? \s*? [0-9]{4,12} \z]x) 26 10 36
46 26 $return = 1;
47 }
48
49 36 return $return;
50 }
51  
52 6 1;
53  
54 __END__
↑ Summary