| 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"
MC/DC100%1/1
$conf->{"format"} ||= "alpha-2"
$conf->{"format"}
Truth table100%2/2
A
A= $conf->{"format"}
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 39 | ▶ | if ( $conf->{format} eq 'alpha-2' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 19 | 16 | ▶ | if ( length $value != 2 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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'
MC/DC100%1/1
$conf->{'lang'} || 'en'
$conf->{'lang'}
Truth table100%2/2
A
A= $conf->{'lang'}
| |||||||||||||||
| 36 | use_io_layer => 1, | ||||||||||||||
| 37 | ); | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 29 | ▶ | if ( $lcm->code2country( $value ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | 17 | return 1; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 12 | return; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 4 | 1; | |||||||||||||
| 47 | |||||||||||||||
| 48 | __END__ | ||||||||||||||