line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Validation::Constraints::Postcode; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
511
|
use namespace::autoclean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
60
|
use Data::Validation::Constants qw( EXCEPTION_CLASS FALSE TRUE ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
223
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends q(Data::Validation::Constraints); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
EXCEPTION_CLASS->add_exception( 'ValidPostcode', { |
11
|
|
|
|
|
|
|
parents => [ 'InvalidParameter' ], |
12
|
|
|
|
|
|
|
error => 'Parameter [_1] is not a valid postcode' } ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my @patterns = ( 'AN NAA', 'ANN NAA', 'AAN NAA', 'AANN NAA', |
15
|
|
|
|
|
|
|
'ANA NAA', 'AANA NAA', 'AAA NAA', ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
for (@patterns) { s{ A }{[A-Z]}gmx; s{ N }{\\d}gmx; s{ [ ] }{\\s+}gmx; } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $pattern = join '|', @patterns; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub validate { |
22
|
7
|
100
|
|
7
|
1
|
9
|
my ($self, $v) = @_; return $v =~ m{ \A (?:$pattern) \z }mox ? TRUE : FALSE; |
|
7
|
|
|
|
|
98
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Local Variables: |
28
|
|
|
|
|
|
|
# mode: perl |
29
|
|
|
|
|
|
|
# tab-width: 3 |
30
|
|
|
|
|
|
|
# End: |