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

filter: Statementstmt 100% 28 / 28 Branchbran 100% 10 / 10 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 50 / 50 CC 8 SCAR 17.3
CC
8
Cov
100%
check
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
↑ Summary
1 package Data::Validate::WithYAML::Plugin::Country;
2  
3 # ABSTRACT: check whether a given value is a valid country code
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Locale::Country::Multilingual;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 our $VERSION = 0.03;
12  
13 39 ▶sub check {
Subroutine check: called CC=8 SCAR=20.8
Pod documented
14 39 my ($class, $value, $conf) = @_;
15  
16 39 ▶ $conf->{format} ||= 'alpha-2';
Condition100%2/2
$conf->{"format"} ||= "alpha-2"
l!l
318
MC/DC100%1/1
$conf->{"format"} ||= "alpha-2"
$conf->{"format"}
Truth table100%2/2
A
A= $conf->{"format"}
Aresult
11
00
17  
18 39 ▶ if ( $conf->{format} eq 'alpha-2' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($conf->{'format'} eq 'alpha-2') { } 16 23 39
elsif ($conf->{'format'} eq 'alpha-3') { } 14 9 23
19 16 ▶ if ( length $value != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value != 2) 6 10 16
20 6 carp "value is not in alpha-2 format";
21 6 return;
22 }
23 }
24 elsif ( $conf->{format} eq 'alpha-3' ) {
25 14 ▶ if ( length $value != 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value != 3) 4 10 14
26 4 carp "value is not in alpha-3 format";
27 4 return;
28 }
29 }
30 else {
31 9 croak "unsupported format " . $conf->{format};
32 }
33  
34 my $lcm = Locale::Country::Multilingual->new(
35 29 ▶ lang => $conf->{lang} || 'en',
Condition100%2/2
$conf->{'lang'} || 'en'
l!l
524
MC/DC100%1/1
$conf->{'lang'} || 'en'
$conf->{'lang'}
Truth table100%2/2
A
A= $conf->{'lang'}
Aresult
11
00
36 use_io_layer => 1,
37 );
38  
39 29 ▶ if ( $lcm->code2country( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lcm->code2country($value)) 17 12 29
40 17 return 1;
41 }
42  
43 12 return;
44 }
45  
46 4 1;
47  
48 __END__
↑ Summary