line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Normal::Type::Zip; |
2
|
9
|
|
|
9
|
|
29
|
use strict; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
184
|
|
3
|
9
|
|
|
9
|
|
26
|
use warnings; |
|
9
|
|
|
|
|
32
|
|
|
9
|
|
|
|
|
1746
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub transform { |
7
|
3
|
|
|
3
|
1
|
8
|
my ($self,$value) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# US 5 or 9 digit zip codes |
10
|
3
|
100
|
|
|
|
21
|
if ( $value =~ /^(\d{5})(?:[\-|\||\.|_|\s]*\d{4})?$/ ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# trim zip9 down to 5 for now |
12
|
|
|
|
|
|
|
# TODO: add separate field for zip9 ( see revision 94419 for original code) |
13
|
2
|
|
|
|
|
11
|
return $1; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
elsif ($value =~ /^(apo|fpo)[\-|\||\.|_|\s]*aa[\-|\||\.|_|\s]*(\d{5})$/) { |
16
|
0
|
|
|
|
|
0
|
return $2; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
# Canada |
19
|
|
|
|
|
|
|
elsif ( $value =~ /^([a-z]\d[a-z])(\s|-|\||\.|_)*(\d[a-z]\d)$/ ) { |
20
|
1
|
|
|
|
|
4
|
$value = join '',$1,$3; |
21
|
1
|
|
|
|
|
4
|
return $value; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
0
|
|
|
|
|
0
|
die "Invalid zip code"; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
30
|
1
|
|
|
|
|
3
|
return bless {@_}, $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |