File Coverage

blib/lib/CGI/Untaint/uk_postcode.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 17 17 100.0


line stmt bran cond sub pod time code
1             package CGI::Untaint::uk_postcode;
2              
3             $VERSION = '1.00';
4              
5 1     1   9683 use strict;
  1         3  
  1         40  
6 1     1   5 use base 'CGI::Untaint::object';
  1         2  
  1         865  
7              
8              
9             sub _untaint_re {
10 36     36   9582 my @patterns = ('ON NII', 'ONN NII', 'OON NII', 'OONN NII',
11             'ONO NII', 'OONO NII', 'OOO NII');
12              
13 36         70 foreach (@patterns) {
14 252         632 s/N/\\d/g;
15 252         691 s/O/[A-Z]/g; # outward code
16 252         764 s/I/[ABDEFGHJLNPQRSTUWXYZ]/g; # inward code
17 252         865 s/ /\\s?/g;
18             }
19              
20 36         120 my $re = join '|', @patterns;
21 36         1678 return qr/^($re)$/i;
22             }
23              
24             =head1 NAME
25              
26             CGI::Untaint::uk_postcode - validate a UK postcode
27              
28             =head1 SYNOPSIS
29              
30             use CGI::Untaint;
31             my $handler = CGI::Untaint->new($q->Vars);
32              
33             my $url = $handler->extract( -as_uk_postcode => 'postcode' );
34              
35             =head1 DESCRIPTION
36              
37             This CGI::Untaint input handler verifies that it is dealing with a
38             reasonably plausible UK postcode, according to some checks by the Royal
39             Mail.
40              
41             Due to the complexities of the UK postal code system it is impossible to
42             accurately check if the postcode is real, or even if it is of a completely
43             valid format. As such there may be false positives. There should not,
44             however, be any false negatives, so if you find any valid postcodes that
45             this rejects, PLEASE let me know.
46              
47             =head1 SEE ALSO
48              
49             http://en.wikipedia.org/wiki/Postcode
50              
51             L
52              
53             =head1 AUTHOR
54              
55             Tony Bowden. Based on original regular expression by Craig Berry.
56              
57             =head1 BUGS and QUERIES
58              
59             Please direct all correspondence regarding this module to:
60             bug-CGI-Untaint-uk_postcode@rt.cpan.org
61              
62             =head1 COPYRIGHT
63              
64             Copyright (C) 2001-2005 Tony Bowden.
65              
66             This program is free software; you can redistribute it and/or modify it under
67             the terms of the GNU General Public License; either version 2 of the License,
68             or (at your option) any later version.
69              
70             This program is distributed in the hope that it will be useful, but WITHOUT
71             ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
72             FOR A PARTICULAR PURPOSE.
73              
74             =cut
75              
76             1;