line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Input::Validator::Condition; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
22145
|
use strict; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
253
|
|
4
|
7
|
|
|
7
|
|
33
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
176
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
31
|
use base 'Input::Validator::Base'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1088
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
6508
|
use Input::Validator::ConstraintBuilder; |
|
7
|
|
|
|
|
24
|
|
|
7
|
|
|
|
|
5684
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub BUILD { |
11
|
7
|
|
|
7
|
0
|
16
|
my $self = shift; |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
50
|
0
|
|
82
|
$self->{then} ||= sub { }; |
|
0
|
|
|
|
|
0
|
|
14
|
7
|
|
50
|
|
|
41
|
$self->{bulks} ||= []; |
15
|
|
|
|
|
|
|
|
16
|
7
|
|
|
|
|
18
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
1
|
23
|
sub regexp { shift->constraint('regexp' => @_) } |
20
|
3
|
|
|
3
|
1
|
9
|
sub length { shift->constraint('length' => @_) } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub when { |
23
|
8
|
|
|
8
|
1
|
92
|
my $self = shift; |
24
|
8
|
100
|
|
|
|
87
|
my $fields = ref $_[0] eq 'ARRAY' ? shift : [@_]; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
37
|
my $bulk = {fields => $fields, constraints => []}; |
27
|
8
|
|
|
|
|
14
|
push @{$self->{bulks}}, $bulk; |
|
8
|
|
|
|
|
76
|
|
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
|
|
40
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub then { |
33
|
4
|
|
|
4
|
1
|
48
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
4
|
100
|
|
|
|
22
|
return $self->{then} unless @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
6
|
$self->{then} = $_[0]; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
9
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub constraint { |
43
|
9
|
|
|
9
|
1
|
18
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
9
|
|
|
|
|
50
|
my $constraint = Input::Validator::ConstraintBuilder->build(@_); |
46
|
|
|
|
|
|
|
|
47
|
9
|
|
|
|
|
23
|
my $bulk = $self->{bulks}->[-1]; |
48
|
9
|
|
|
|
|
14
|
push @{$bulk->{constraints}}, $constraint; |
|
9
|
|
|
|
|
23
|
|
49
|
|
|
|
|
|
|
|
50
|
9
|
|
|
|
|
53
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
9
|
|
|
9
|
0
|
104
|
sub is_matched { shift->{matched} } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub match { |
56
|
31
|
|
|
31
|
1
|
75
|
my $self = shift; |
57
|
31
|
|
|
|
|
36
|
my $params = shift; |
58
|
|
|
|
|
|
|
|
59
|
31
|
|
|
|
|
34
|
foreach my $bulk (@{$self->{bulks}}) { |
|
31
|
|
|
|
|
134
|
|
60
|
33
|
|
|
|
|
37
|
foreach my $name (@{$bulk->{fields}}) { |
|
33
|
|
|
|
|
66
|
|
61
|
39
|
|
|
|
|
61
|
my $field = $params->{$name}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# No field |
64
|
39
|
100
|
|
|
|
152
|
return 0 unless $field; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Field has already an error |
67
|
30
|
100
|
|
|
|
90
|
return 0 if $field->error; |
68
|
|
|
|
|
|
|
|
69
|
29
|
|
|
|
|
85
|
my $values = $field->value; |
70
|
29
|
100
|
|
|
|
98
|
$values = [$values] unless ref($values) eq 'ARRAY'; |
71
|
|
|
|
|
|
|
|
72
|
29
|
|
|
|
|
53
|
foreach my $value (@$values) { |
73
|
30
|
100
|
100
|
|
|
160
|
return 0 unless defined($value) && $value ne ''; |
74
|
|
|
|
|
|
|
|
75
|
25
|
|
|
|
|
37
|
foreach my $c (@{$bulk->{constraints}}) { |
|
25
|
|
|
|
|
89
|
|
76
|
17
|
|
|
|
|
54
|
my ($ok, $error) = $c->is_valid($value); |
77
|
17
|
100
|
|
|
|
104
|
return 0 unless $ok; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
9
|
|
|
|
|
23
|
$self->{matched} = 1; |
84
|
|
|
|
|
|
|
|
85
|
9
|
|
|
|
|
42
|
return 1; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
__END__ |