Subject: | [PATCH] Valid postcodes containing '0' considered invalid |
Geo::Postcode's 'valid' tests "$a && $d && $s && $u". For real postcodes like "N20 0AD", $s eq "0", which is false, so 'valid' thinks the postcode is invalid.
The attached patch changes 'valid' and 'valid_fragment' to test definedness instead of truth. It also, unrelatedly, fixes a use-of-uninitialised-variable warning in calls to 'location_class'.
Thanks,
Philip (@zaynar.demon.co.uk)
--- Postcode.pm.old 2006-01-07 20:49:46.000000000 +0000
+++ Postcode.pm 2006-01-07 21:01:28.000000000 +0000
@@ -163,7 +163,7 @@
sub location_class {
my $self = shift;
my $class = shift;
- if (defined $class && $class ne $self->{location_class}) {
+ if (defined $class && (!defined $self->{location_class} || $class ne $self->{location_class})) {
$self->{location} = undef;
return $self->{location_class} = $class;
}
@@ -305,7 +305,7 @@
return $self if $self->_special_case;
my ($a, $d, $s, $u) = @{ $self->fragments };
- return unless $a && $d && $s && $u;
+ return unless defined $a && defined $d && defined $s && defined $u;
return if length($a) > 2;
return if $a =~ /[\W\d]/;
return if $a =~ /^[QVX]/;
@@ -332,20 +332,20 @@
return 1 if $self->_special_case;
my ($a, $d, $s, $u) = @{ $self->fragments };
- return unless $a;
+ return unless defined $a;
return if length($a) > 2;
return if $a =~ /[\W\d]/;
return if $a =~ /^[QVX]/;
return if $a =~ /^.[IJZ]/;
- return 1 unless $d || $s || $u;
+ return 1 unless defined $d || defined $s || defined $u;
return if length($a) == 1 && $d !~ /\d[\dABCDEFGHJKSTUW]?/;
return if length($a) == 2 && $d !~ /\d[\dABEHMNPRVWXY]?/;
- return 1 unless $s || $u;
+ return 1 unless defined $s || defined $u;
return if length($s) > 1;
return if $s =~ /\D/;
- return 1 unless $u;
+ return 1 unless defined $u;
return if length($u) != 2;
return if $u =~ /[^A-Z]/;