line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Configuration Class for Validation Classes |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Validation::Class::Configuration provides a default configuration profile used |
4
|
|
|
|
|
|
|
# by validation classes and many class prototype methods. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Validation::Class::Configuration; |
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
748
|
use strict; |
|
109
|
|
|
|
|
268
|
|
|
109
|
|
|
|
|
3224
|
|
9
|
109
|
|
|
109
|
|
588
|
use warnings; |
|
109
|
|
|
|
|
257
|
|
|
109
|
|
|
|
|
2772
|
|
10
|
|
|
|
|
|
|
|
11
|
109
|
|
|
109
|
|
49269
|
use Validation::Class::Directives; |
|
109
|
|
|
|
|
360
|
|
|
109
|
|
|
|
|
4817
|
|
12
|
109
|
|
|
109
|
|
48649
|
use Validation::Class::Listing; |
|
109
|
|
|
|
|
336
|
|
|
109
|
|
|
|
|
3553
|
|
13
|
109
|
|
|
109
|
|
735
|
use Validation::Class::Mapping; |
|
109
|
|
|
|
|
248
|
|
|
109
|
|
|
|
|
2637
|
|
14
|
109
|
|
|
109
|
|
46260
|
use Validation::Class::Fields; |
|
109
|
|
|
|
|
325
|
|
|
109
|
|
|
|
|
3679
|
|
15
|
109
|
|
|
109
|
|
46195
|
use Validation::Class::Mixins; |
|
109
|
|
|
|
|
345
|
|
|
109
|
|
|
|
|
3524
|
|
16
|
109
|
|
|
109
|
|
770
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
252
|
|
|
109
|
|
|
|
|
498
|
|
17
|
|
|
|
|
|
|
|
18
|
109
|
|
|
109
|
|
706
|
use Module::Find 'usesub'; |
|
109
|
|
|
|
|
291
|
|
|
109
|
|
|
|
|
123844
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub attributes { |
23
|
|
|
|
|
|
|
|
24
|
181
|
|
|
181
|
0
|
547
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
181
|
|
|
|
|
540
|
return $self->profile->{ATTRIBUTES}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub builders { |
31
|
|
|
|
|
|
|
|
32
|
171
|
|
|
171
|
0
|
603
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
171
|
|
|
|
|
602
|
return $self->profile->{BUILDERS}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub configure_profile { |
39
|
|
|
|
|
|
|
|
40
|
320
|
|
|
320
|
0
|
904
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
320
|
|
|
|
|
1104
|
$self->configure_profile_register_directives; |
43
|
320
|
|
|
|
|
1295
|
$self->configure_profile_register_filters; |
44
|
320
|
|
|
|
|
1232
|
$self->configure_profile_register_events; |
45
|
|
|
|
|
|
|
|
46
|
320
|
|
|
|
|
1274
|
return $self; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub configure_profile_register_directives { |
51
|
|
|
|
|
|
|
|
52
|
320
|
|
|
320
|
0
|
713
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# automatically attach discovered directive classes |
55
|
|
|
|
|
|
|
|
56
|
320
|
|
|
|
|
1487
|
my $directives = Validation::Class::Directives->new; |
57
|
|
|
|
|
|
|
|
58
|
320
|
|
|
|
|
1421
|
foreach my $directive ($directives->values) { |
59
|
|
|
|
|
|
|
|
60
|
14720
|
|
|
|
|
34952
|
my $name = $directive->name; |
61
|
|
|
|
|
|
|
|
62
|
14720
|
|
|
|
|
28286
|
$self->directives->add($name => $directive); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
320
|
|
|
|
|
2695
|
return $self; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub configure_profile_register_filters { |
71
|
|
|
|
|
|
|
|
72
|
320
|
|
|
320
|
0
|
778
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# automatically attach filters registered on in the filters directive |
75
|
|
|
|
|
|
|
|
76
|
320
|
|
|
|
|
814
|
my $directives = $self->directives; |
77
|
|
|
|
|
|
|
|
78
|
320
|
|
|
|
|
1202
|
my $filters = $directives->get('filters'); |
79
|
|
|
|
|
|
|
|
80
|
320
|
50
|
|
|
|
1107
|
return unless $filters; |
81
|
|
|
|
|
|
|
|
82
|
320
|
|
|
|
|
1438
|
$self->filters->add($filters->registry); |
83
|
|
|
|
|
|
|
|
84
|
320
|
|
|
|
|
768
|
return $self; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub configure_profile_register_events { |
89
|
|
|
|
|
|
|
|
90
|
320
|
|
|
320
|
0
|
814
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# inspect the directives for event subscriptions |
93
|
|
|
|
|
|
|
|
94
|
320
|
50
|
|
|
|
872
|
if (my @directives = ($self->directives->values)) { |
95
|
|
|
|
|
|
|
|
96
|
320
|
|
|
|
|
2183
|
my $events = { |
97
|
|
|
|
|
|
|
# hookable events list, keyed by directive name |
98
|
|
|
|
|
|
|
'on_after_validation' => {}, |
99
|
|
|
|
|
|
|
'on_before_validation' => {}, |
100
|
|
|
|
|
|
|
'on_normalize' => {}, |
101
|
|
|
|
|
|
|
'on_validate' => {} |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
320
|
|
|
|
|
772
|
while (my($name, $container) = each(%{$events})) { |
|
1600
|
|
|
|
|
5644
|
|
105
|
|
|
|
|
|
|
|
106
|
1280
|
|
|
|
|
6151
|
($name) = $name =~ /^on_(\w+)/; |
107
|
|
|
|
|
|
|
|
108
|
1280
|
|
|
|
|
2918
|
foreach my $directive (@directives) { |
109
|
58892
|
50
|
|
|
|
113312
|
next if defined $container->{$name}; |
110
|
58892
|
100
|
|
|
|
203208
|
if (my $routine = $directive->can($name)) { |
111
|
21763
|
|
|
|
|
46584
|
$container->{$directive->name} = $routine; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
320
|
|
|
|
|
1243
|
$self->events->add($events); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
320
|
|
|
|
|
1233
|
return $self; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub default_profile { |
126
|
|
|
|
|
|
|
|
127
|
153
|
|
|
153
|
0
|
1703
|
my %default_mixins = ( |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
':flg' => Validation::Class::Mixin->new( |
130
|
|
|
|
|
|
|
required => 1, |
131
|
|
|
|
|
|
|
min_length => 1, |
132
|
|
|
|
|
|
|
filters => [qw/trim strip numeric/], |
133
|
|
|
|
|
|
|
between => [0, 1], |
134
|
|
|
|
|
|
|
name => ':flg', |
135
|
|
|
|
|
|
|
), |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
':num' => Validation::Class::Mixin->new( |
138
|
|
|
|
|
|
|
required => 1, |
139
|
|
|
|
|
|
|
min_length => 1, |
140
|
|
|
|
|
|
|
filters => [qw/trim strip numeric/], |
141
|
|
|
|
|
|
|
name => ':num', |
142
|
|
|
|
|
|
|
), |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
':str' => Validation::Class::Mixin->new( |
145
|
|
|
|
|
|
|
required => 1, |
146
|
|
|
|
|
|
|
min_length => 1, |
147
|
|
|
|
|
|
|
filters => [qw/trim strip/], |
148
|
|
|
|
|
|
|
name => ':str', |
149
|
|
|
|
|
|
|
) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
153
|
|
|
|
|
871
|
return Validation::Class::Mapping->new({ |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
ATTRIBUTES => Validation::Class::Mapping->new, |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
BUILDERS => Validation::Class::Listing->new, |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
DIRECTIVES => Validation::Class::Mapping->new, |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
DOCUMENTS => Validation::Class::Mapping->new, |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
EVENTS => Validation::Class::Mapping->new, |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
FIELDS => Validation::Class::Fields->new, |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
FILTERS => Validation::Class::Mapping->new, |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
METHODS => Validation::Class::Mapping->new, |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
MIXINS => Validation::Class::Mixins->new(%default_mixins), |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
PROFILES => Validation::Class::Mapping->new, |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
SETTINGS => Validation::Class::Mapping->new, |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
}); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub directives { |
182
|
|
|
|
|
|
|
|
183
|
15530
|
|
|
15530
|
0
|
25390
|
my ($self) = @_; |
184
|
|
|
|
|
|
|
|
185
|
15530
|
|
|
|
|
25082
|
return $self->profile->{DIRECTIVES}; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub documents { |
190
|
|
|
|
|
|
|
|
191
|
179
|
|
|
179
|
0
|
689
|
my ($self) = @_; |
192
|
|
|
|
|
|
|
|
193
|
179
|
|
|
|
|
605
|
return $self->profile->{DOCUMENTS}; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub events { |
198
|
|
|
|
|
|
|
|
199
|
487
|
|
|
487
|
0
|
1228
|
my ($self) = @_; |
200
|
|
|
|
|
|
|
|
201
|
487
|
|
|
|
|
1241
|
return $self->profile->{EVENTS}; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub fields { |
206
|
|
|
|
|
|
|
|
207
|
324
|
|
|
324
|
0
|
917
|
my ($self) = @_; |
208
|
|
|
|
|
|
|
|
209
|
324
|
|
|
|
|
889
|
return $self->profile->{FIELDS}; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub filters { |
214
|
|
|
|
|
|
|
|
215
|
488
|
|
|
488
|
0
|
1162
|
my ($self) = @_; |
216
|
|
|
|
|
|
|
|
217
|
488
|
|
|
|
|
1195
|
return $self->profile->{FILTERS}; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub methods { |
222
|
|
|
|
|
|
|
|
223
|
186
|
|
|
186
|
0
|
757
|
my ($self) = @_; |
224
|
|
|
|
|
|
|
|
225
|
186
|
|
|
|
|
605
|
return $self->profile->{METHODS}; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub mixins { |
230
|
|
|
|
|
|
|
|
231
|
186
|
|
|
186
|
0
|
685
|
my ($self) = @_; |
232
|
|
|
|
|
|
|
|
233
|
186
|
|
|
|
|
660
|
return $self->profile->{MIXINS}; |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub new { |
238
|
|
|
|
|
|
|
|
239
|
153
|
|
|
153
|
0
|
579
|
my $self = bless {}, shift; |
240
|
|
|
|
|
|
|
|
241
|
153
|
|
|
|
|
693
|
$self->configure_profile; |
242
|
|
|
|
|
|
|
|
243
|
153
|
|
|
|
|
874
|
return $self; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub profile { |
248
|
|
|
|
|
|
|
|
249
|
18135
|
|
|
18135
|
0
|
29142
|
my ($self) = @_; |
250
|
|
|
|
|
|
|
|
251
|
18135
|
|
66
|
|
|
67338
|
return $self->{profile} ||= $self->default_profile; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub profiles { |
256
|
|
|
|
|
|
|
|
257
|
178
|
|
|
178
|
0
|
639
|
my ($self) = @_; |
258
|
|
|
|
|
|
|
|
259
|
178
|
|
|
|
|
654
|
return $self->profile->{PROFILES}; |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub settings { |
264
|
|
|
|
|
|
|
|
265
|
201
|
|
|
201
|
0
|
681
|
my ($self) = @_; |
266
|
|
|
|
|
|
|
|
267
|
201
|
|
|
|
|
746
|
return $self->profile->{SETTINGS}; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
1; |