line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Validate::WithYAML::Plugin::Country; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: check whether a given value is a valid country code |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
23652
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
91
|
|
9
|
1
|
|
|
1
|
|
987
|
use Locale::Country::Multilingual; |
|
1
|
|
|
|
|
5279
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.02; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub check { |
14
|
16
|
|
|
16
|
0
|
5552
|
my ($class, $value, $conf) = @_; |
15
|
|
|
|
|
|
|
|
16
|
16
|
|
100
|
|
|
81
|
$conf->{format} ||= 'alpha-2'; |
17
|
|
|
|
|
|
|
|
18
|
16
|
50
|
|
|
|
49
|
if ( $conf->{format} eq 'alpha-2' ) { |
|
|
0
|
|
|
|
|
|
19
|
16
|
100
|
|
|
|
43
|
if ( length $value != 2 ) { |
20
|
6
|
|
|
|
|
886
|
carp "value is not in alpha-2 format"; |
21
|
6
|
|
|
|
|
131
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
elsif ( $conf->{format} eq 'alpha-3' ) { |
25
|
0
|
0
|
|
|
|
0
|
if ( length $value != 3 ) { |
26
|
0
|
|
|
|
|
0
|
carp "value is not in alpha-3 format"; |
27
|
0
|
|
|
|
|
0
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
0
|
|
|
|
|
0
|
croak "unsupported format " . $conf->{format}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
50
|
|
|
81
|
my $lcm = Locale::Country::Multilingual->new( |
35
|
|
|
|
|
|
|
lang => $conf->{lang} || 'en', |
36
|
|
|
|
|
|
|
use_io_layer => 1, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
10
|
100
|
|
|
|
151
|
if ( $lcm->code2country( $value ) ) { |
40
|
6
|
|
|
|
|
43679
|
return 1; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
130
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |