line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::CheckArgs::country; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# to-do: allow more options for entering a country? |
4
|
|
|
|
|
|
|
# would require expanding on Geography::Countries, or |
5
|
|
|
|
|
|
|
# doing some fuzzier matching on country name |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base 'HTML::CheckArgs::Object'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1598
|
|
11
|
1
|
|
|
1
|
|
1018
|
use Geography::Countries; |
|
1
|
|
|
|
|
103988
|
|
|
1
|
|
|
|
|
110
|
|
12
|
1
|
|
|
1
|
|
586
|
use HTML::FormatData; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_valid { |
15
|
|
|
|
|
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $value = $self->value; |
18
|
|
|
|
|
|
|
my $config = $self->config; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$self->check_params( required => [], optional => [], cleanable => 1 ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# no value passed in |
23
|
|
|
|
|
|
|
if ( $config->{required} && !$value ) { |
24
|
|
|
|
|
|
|
$self->error_code( 'country_00' ); # required |
25
|
|
|
|
|
|
|
$self->error_message( 'Not given.' ); |
26
|
|
|
|
|
|
|
return; |
27
|
|
|
|
|
|
|
} elsif ( !$config->{required} && !$value ) { |
28
|
|
|
|
|
|
|
return 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# clean it up for validation |
32
|
|
|
|
|
|
|
$value =~ s/\.//g; # for U.S. case |
33
|
|
|
|
|
|
|
$value = HTML::FormatData->new->format_text( |
34
|
|
|
|
|
|
|
$value, clean_whitespace => 1, strip_html => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# match two-letter abbrieviation or name |
38
|
|
|
|
|
|
|
# matching on name is extremely fragile, and should never be done |
39
|
|
|
|
|
|
|
my ( $abbr, undef, undef, $name, undef ) = country( $value ); |
40
|
|
|
|
|
|
|
unless ( lc( $value ) eq lc( $abbr ) or lc( $value ) eq lc( $name ) ) { |
41
|
|
|
|
|
|
|
$self->error_code( 'country_01' ); |
42
|
|
|
|
|
|
|
$self->error_message( 'Not valid country; please enter canonical country name or two-letter abbrieviation.' ); |
43
|
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# return cleaned value (the 2-letter abbr)? |
47
|
|
|
|
|
|
|
unless ( $config->{noclean} ) { |
48
|
|
|
|
|
|
|
$self->value( $abbr ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |