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
|
|
591
|
use strict; |
|
109
|
|
|
|
|
201
|
|
|
109
|
|
|
|
|
2681
|
|
9
|
109
|
|
|
109
|
|
472
|
use warnings; |
|
109
|
|
|
|
|
207
|
|
|
109
|
|
|
|
|
2323
|
|
10
|
|
|
|
|
|
|
|
11
|
109
|
|
|
109
|
|
39214
|
use Validation::Class::Directives; |
|
109
|
|
|
|
|
338
|
|
|
109
|
|
|
|
|
4074
|
|
12
|
109
|
|
|
109
|
|
41858
|
use Validation::Class::Listing; |
|
109
|
|
|
|
|
287
|
|
|
109
|
|
|
|
|
3052
|
|
13
|
109
|
|
|
109
|
|
710
|
use Validation::Class::Mapping; |
|
109
|
|
|
|
|
198
|
|
|
109
|
|
|
|
|
2156
|
|
14
|
109
|
|
|
109
|
|
39598
|
use Validation::Class::Fields; |
|
109
|
|
|
|
|
280
|
|
|
109
|
|
|
|
|
3148
|
|
15
|
109
|
|
|
109
|
|
40990
|
use Validation::Class::Mixins; |
|
109
|
|
|
|
|
301
|
|
|
109
|
|
|
|
|
3200
|
|
16
|
109
|
|
|
109
|
|
757
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
209
|
|
|
109
|
|
|
|
|
410
|
|
17
|
|
|
|
|
|
|
|
18
|
109
|
|
|
109
|
|
555
|
use Module::Find 'usesub'; |
|
109
|
|
|
|
|
218
|
|
|
109
|
|
|
|
|
101876
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '7.900058'; # VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub attributes { |
23
|
|
|
|
|
|
|
|
24
|
181
|
|
|
181
|
0
|
449
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
181
|
|
|
|
|
463
|
return $self->profile->{ATTRIBUTES}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub builders { |
31
|
|
|
|
|
|
|
|
32
|
171
|
|
|
171
|
0
|
497
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
171
|
|
|
|
|
532
|
return $self->profile->{BUILDERS}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub configure_profile { |
39
|
|
|
|
|
|
|
|
40
|
320
|
|
|
320
|
0
|
697
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
320
|
|
|
|
|
944
|
$self->configure_profile_register_directives; |
43
|
320
|
|
|
|
|
1058
|
$self->configure_profile_register_filters; |
44
|
320
|
|
|
|
|
1038
|
$self->configure_profile_register_events; |
45
|
|
|
|
|
|
|
|
46
|
320
|
|
|
|
|
1387
|
return $self; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub configure_profile_register_directives { |
51
|
|
|
|
|
|
|
|
52
|
320
|
|
|
320
|
0
|
634
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# automatically attach discovered directive classes |
55
|
|
|
|
|
|
|
|
56
|
320
|
|
|
|
|
1393
|
my $directives = Validation::Class::Directives->new; |
57
|
|
|
|
|
|
|
|
58
|
320
|
|
|
|
|
1186
|
foreach my $directive ($directives->values) { |
59
|
|
|
|
|
|
|
|
60
|
14720
|
|
|
|
|
28362
|
my $name = $directive->name; |
61
|
|
|
|
|
|
|
|
62
|
14720
|
|
|
|
|
22908
|
$self->directives->add($name => $directive); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
320
|
|
|
|
|
2353
|
return $self; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub configure_profile_register_filters { |
71
|
|
|
|
|
|
|
|
72
|
320
|
|
|
320
|
0
|
662
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# automatically attach filters registered on in the filters directive |
75
|
|
|
|
|
|
|
|
76
|
320
|
|
|
|
|
660
|
my $directives = $self->directives; |
77
|
|
|
|
|
|
|
|
78
|
320
|
|
|
|
|
996
|
my $filters = $directives->get('filters'); |
79
|
|
|
|
|
|
|
|
80
|
320
|
50
|
|
|
|
954
|
return unless $filters; |
81
|
|
|
|
|
|
|
|
82
|
320
|
|
|
|
|
860
|
$self->filters->add($filters->registry); |
83
|
|
|
|
|
|
|
|
84
|
320
|
|
|
|
|
577
|
return $self; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub configure_profile_register_events { |
89
|
|
|
|
|
|
|
|
90
|
320
|
|
|
320
|
0
|
636
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# inspect the directives for event subscriptions |
93
|
|
|
|
|
|
|
|
94
|
320
|
50
|
|
|
|
735
|
if (my @directives = ($self->directives->values)) { |
95
|
|
|
|
|
|
|
|
96
|
320
|
|
|
|
|
1642
|
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
|
|
|
|
|
643
|
while (my($name, $container) = each(%{$events})) { |
|
1600
|
|
|
|
|
4766
|
|
105
|
|
|
|
|
|
|
|
106
|
1280
|
|
|
|
|
5545
|
($name) = $name =~ /^on_(\w+)/; |
107
|
|
|
|
|
|
|
|
108
|
1280
|
|
|
|
|
2404
|
foreach my $directive (@directives) { |
109
|
58892
|
50
|
|
|
|
92782
|
next if defined $container->{$name}; |
110
|
58892
|
100
|
|
|
|
159975
|
if (my $routine = $directive->can($name)) { |
111
|
21763
|
|
|
|
|
38078
|
$container->{$directive->name} = $routine; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
320
|
|
|
|
|
1061
|
$self->events->add($events); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
320
|
|
|
|
|
1072
|
return $self; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub default_profile { |
126
|
|
|
|
|
|
|
|
127
|
153
|
|
|
153
|
0
|
1394
|
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
|
|
|
|
|
685
|
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
|
20383
|
my ($self) = @_; |
184
|
|
|
|
|
|
|
|
185
|
15530
|
|
|
|
|
20582
|
return $self->profile->{DIRECTIVES}; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub documents { |
190
|
|
|
|
|
|
|
|
191
|
179
|
|
|
179
|
0
|
524
|
my ($self) = @_; |
192
|
|
|
|
|
|
|
|
193
|
179
|
|
|
|
|
532
|
return $self->profile->{DOCUMENTS}; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub events { |
198
|
|
|
|
|
|
|
|
199
|
487
|
|
|
487
|
0
|
967
|
my ($self) = @_; |
200
|
|
|
|
|
|
|
|
201
|
487
|
|
|
|
|
1076
|
return $self->profile->{EVENTS}; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub fields { |
206
|
|
|
|
|
|
|
|
207
|
324
|
|
|
324
|
0
|
733
|
my ($self) = @_; |
208
|
|
|
|
|
|
|
|
209
|
324
|
|
|
|
|
731
|
return $self->profile->{FIELDS}; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub filters { |
214
|
|
|
|
|
|
|
|
215
|
488
|
|
|
488
|
0
|
926
|
my ($self) = @_; |
216
|
|
|
|
|
|
|
|
217
|
488
|
|
|
|
|
1193
|
return $self->profile->{FILTERS}; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub methods { |
222
|
|
|
|
|
|
|
|
223
|
186
|
|
|
186
|
0
|
523
|
my ($self) = @_; |
224
|
|
|
|
|
|
|
|
225
|
186
|
|
|
|
|
503
|
return $self->profile->{METHODS}; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub mixins { |
230
|
|
|
|
|
|
|
|
231
|
186
|
|
|
186
|
0
|
543
|
my ($self) = @_; |
232
|
|
|
|
|
|
|
|
233
|
186
|
|
|
|
|
542
|
return $self->profile->{MIXINS}; |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub new { |
238
|
|
|
|
|
|
|
|
239
|
153
|
|
|
153
|
0
|
476
|
my $self = bless {}, shift; |
240
|
|
|
|
|
|
|
|
241
|
153
|
|
|
|
|
608
|
$self->configure_profile; |
242
|
|
|
|
|
|
|
|
243
|
153
|
|
|
|
|
1126
|
return $self; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub profile { |
248
|
|
|
|
|
|
|
|
249
|
18135
|
|
|
18135
|
0
|
22515
|
my ($self) = @_; |
250
|
|
|
|
|
|
|
|
251
|
18135
|
|
66
|
|
|
55360
|
return $self->{profile} ||= $self->default_profile; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub profiles { |
256
|
|
|
|
|
|
|
|
257
|
178
|
|
|
178
|
0
|
493
|
my ($self) = @_; |
258
|
|
|
|
|
|
|
|
259
|
178
|
|
|
|
|
511
|
return $self->profile->{PROFILES}; |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub settings { |
264
|
|
|
|
|
|
|
|
265
|
201
|
|
|
201
|
0
|
558
|
my ($self) = @_; |
266
|
|
|
|
|
|
|
|
267
|
201
|
|
|
|
|
588
|
return $self->profile->{SETTINGS}; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
1; |