line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Pattern Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Pattern; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
52686
|
use strict; |
|
109
|
|
|
|
|
312
|
|
|
109
|
|
|
|
|
3191
|
|
6
|
109
|
|
|
109
|
|
603
|
use warnings; |
|
109
|
|
|
|
|
248
|
|
|
109
|
|
|
|
|
2850
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
577
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
249
|
|
|
109
|
|
|
|
|
10076
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
771
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
273
|
|
|
109
|
|
|
|
|
660
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 1; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
has 'message' => '%s is not formatted properly'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub validate { |
21
|
|
|
|
|
|
|
|
22
|
25
|
|
|
25
|
0
|
125
|
my ($self, $proto, $field, $param) = @_; |
23
|
|
|
|
|
|
|
|
24
|
25
|
50
|
33
|
|
|
156
|
if (defined $field->{pattern} && defined $param) { |
25
|
|
|
|
|
|
|
|
26
|
25
|
|
|
|
|
71
|
my $pattern = $field->{pattern}; |
27
|
|
|
|
|
|
|
|
28
|
25
|
50
|
66
|
|
|
113
|
if ($field->{required} || $param) { |
29
|
|
|
|
|
|
|
|
30
|
25
|
100
|
|
|
|
90
|
unless ( isa_regexp($pattern) ) { |
31
|
|
|
|
|
|
|
|
32
|
10
|
|
|
|
|
80
|
$pattern =~ s/([^#X ])/\\$1/g; |
33
|
10
|
|
|
|
|
64
|
$pattern =~ s/#/\\d/g; |
34
|
10
|
|
|
|
|
40
|
$pattern =~ s/X/[a-zA-Z]/g; |
35
|
10
|
|
|
|
|
110
|
$pattern = qr/$pattern/; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
25
|
100
|
|
|
|
494
|
unless ( $param =~ $pattern ) { |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
63
|
$self->error($proto, $field); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
25
|
|
|
|
|
83
|
return $self; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |