line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Validation::Constraints::Postcode; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
846
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
106
|
use Data::Validation::Constants qw( EXCEPTION_CLASS FALSE TRUE ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
6
|
1
|
|
|
1
|
|
436
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
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
|
20
|
my ($self, $v) = @_; return $v =~ m{ \A (?:$pattern) \z }mox ? TRUE : FALSE; |
|
7
|
|
|
|
|
137
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Local Variables: |
28
|
|
|
|
|
|
|
# mode: perl |
29
|
|
|
|
|
|
|
# tab-width: 3 |
30
|
|
|
|
|
|
|
# End: |