line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Minimalist Data Validation for Moo |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package MooX::Validate; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
40904
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
22
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
18
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
767
|
use Validation::Class::Simple; |
|
1
|
|
|
|
|
264428
|
|
|
1
|
|
|
|
|
234
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.000003'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %MAKERS = (); # this is meant to be pithy, mst-- |
14
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
15
|
|
|
|
|
|
|
our @EXPORT = qw(has); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
144
|
my $class = shift; |
20
|
2
|
|
|
|
|
83
|
my $target = caller; |
21
|
2
|
|
|
|
|
8
|
my $maker = $MAKERS{$target} = {}; |
22
|
|
|
|
|
|
|
|
23
|
2
|
100
|
|
|
|
39
|
if (my $has = $target->can('has')) { |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
82
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
26
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
478
|
|
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
6
|
*{"$target\::has"} = sub { |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
1800
|
my ($name, %config) = @_; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
6
|
my $validation = delete $config{'validate'}; |
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
33
|
|
|
23
|
my $build_coercion = 1 if |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
35
|
|
|
|
|
|
|
!$config{'coerce'} && |
36
|
|
|
|
|
|
|
(($validation and "HASH" eq ref $validation) and |
37
|
|
|
|
|
|
|
exists $validation->{filters}) |
38
|
|
|
|
|
|
|
; |
39
|
|
|
|
|
|
|
|
40
|
1
|
50
|
33
|
|
|
26
|
my $build_validation = 1 if |
|
|
|
33
|
|
|
|
|
41
|
|
|
|
|
|
|
!$config{'isa'} && |
42
|
|
|
|
|
|
|
($validation and "HASH" eq ref $validation) |
43
|
|
|
|
|
|
|
; |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
5
|
if ($build_coercion) { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$config{'coerce'} = sub { |
48
|
|
|
|
|
|
|
|
49
|
2
|
50
|
|
2
|
|
41673
|
my $parameter = @_ > 2 ? [@_] : $_[0]; |
50
|
2
|
|
|
|
|
26
|
my $validator = Validation::Class::Simple->new( |
51
|
|
|
|
|
|
|
report_failure => 1, |
52
|
|
|
|
|
|
|
report_unknown => 1, |
53
|
|
|
|
|
|
|
ignore_failure => 0, |
54
|
|
|
|
|
|
|
ignore_unknown => 0, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
23194
|
$validator->fields->add($name, $validation); |
58
|
2
|
|
|
|
|
256
|
$validator->params->add($name, $parameter); |
59
|
2
|
|
|
|
|
1208
|
$validator->prototype->normalize($validator); |
60
|
2
|
|
|
|
|
5514
|
$validator->params->get($name); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
8
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
|
|
|
6
|
if ($build_validation) { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$config{'isa'} = sub { |
69
|
|
|
|
|
|
|
|
70
|
2
|
50
|
|
2
|
|
236
|
my $parameter = @_ > 2 ? [@_] : $_[0]; |
71
|
2
|
|
|
|
|
13
|
my $validator = Validation::Class::Simple->new( |
72
|
|
|
|
|
|
|
report_failure => 1, |
73
|
|
|
|
|
|
|
report_unknown => 1, |
74
|
|
|
|
|
|
|
ignore_failure => 0, |
75
|
|
|
|
|
|
|
ignore_unknown => 0, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
21412
|
$validator->fields->add($name, $validation); |
79
|
2
|
|
|
|
|
248
|
$validator->params->add($name, $parameter); |
80
|
|
|
|
|
|
|
|
81
|
2
|
100
|
|
|
|
1174
|
die $validator->errors_to_string |
82
|
|
|
|
|
|
|
unless $validator->validate($name); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# defer |
85
|
1
|
|
|
|
|
15085
|
$maker->{$name} = |
86
|
|
|
|
|
|
|
{rules => $validation, params => $parameter} |
87
|
|
|
|
|
|
|
; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
7
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
8
|
return $has->($name, %config); |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
7
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
2
|
50
|
|
|
|
20
|
unless ($target->can('validator')) { |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
28
|
|
102
|
1
|
|
|
1
|
|
6
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
298
|
|
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
9
|
*{"$target\::validator"} = sub { |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
1
|
|
12249
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
3
|
my $class = ref $self; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
9
|
my $validator = Validation::Class::Simple->new( |
111
|
|
|
|
|
|
|
report_failure => 1, |
112
|
|
|
|
|
|
|
report_unknown => 1, |
113
|
|
|
|
|
|
|
ignore_failure => 0, |
114
|
|
|
|
|
|
|
ignore_unknown => 0, |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
10269
|
while (my($name, $config) = each(%{$maker})) { |
|
2
|
|
|
|
|
650
|
|
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
4
|
my $validation = $config->{rules}; |
120
|
1
|
|
|
|
|
5
|
my $parameter = $config->{params}; |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
4
|
$validator->fields->add($name, $validation); |
123
|
1
|
|
|
|
|
114
|
$validator->params->add($name, $parameter); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
8
|
return $validator; |
128
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
21
|
}; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
2
|
|
|
|
|
3039
|
return; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |