line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Venus::Schema; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21
|
use 5.018; |
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Venus::Class 'attr', 'base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
base 'Venus::Kind::Utility'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ATTRIBUTES |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
attr 'definition'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# BUILDERS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub build_args { |
19
|
21
|
|
|
21
|
0
|
43
|
my ($self, $data) = @_; |
20
|
|
|
|
|
|
|
|
21
|
21
|
0
|
33
|
|
|
73
|
if (keys %$data == 1 && exists $data->{definition}) { |
22
|
0
|
|
|
|
|
0
|
return $data; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
return { |
25
|
21
|
|
|
|
|
68
|
definition => $data, |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub assert { |
32
|
18
|
|
|
18
|
1
|
42
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
18
|
|
|
|
|
764
|
require Venus::Assert; |
35
|
|
|
|
|
|
|
|
36
|
18
|
|
|
|
|
86
|
my $assert = Venus::Assert->new('schema'); |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
59
|
return $assert->expression($assert->render('hashkeys', $self->definition)); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub check { |
42
|
4
|
|
|
4
|
1
|
10
|
my ($self, $data) = @_; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
8
|
my $assert = $self->assert; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
14
|
return $assert->check($data); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub deduce { |
50
|
4
|
|
|
4
|
1
|
10
|
my ($self, $data) = @_; |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
16
|
require Venus::Type; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
11
|
my $assert = $self->assert; |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
17
|
return Venus::Type->new($assert->validate($data))->deduce_deep; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub error { |
60
|
4
|
|
|
4
|
1
|
9
|
my ($self, $data) = @_; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
29
|
my $error = $self->catch('validate', $data); |
63
|
|
|
|
|
|
|
|
64
|
4
|
50
|
66
|
|
|
15
|
die $error if $error && !$error->isa('Venus::Assert::Error'); |
65
|
|
|
|
|
|
|
|
66
|
4
|
|
|
|
|
27
|
return $error; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub validate { |
70
|
8
|
|
|
8
|
1
|
23
|
my ($self, $data) = @_; |
71
|
|
|
|
|
|
|
|
72
|
8
|
|
|
|
|
20
|
my $assert = $self->assert; |
73
|
|
|
|
|
|
|
|
74
|
8
|
|
|
|
|
40
|
return $assert->validate($data); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Venus::Schema - Schema Class |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 ABSTRACT |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Schema Class for Perl 5 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SYNOPSIS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
package main; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Venus::Schema; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $schema = Venus::Schema->new; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# bless({...}, 'Venus::Schema') |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 DESCRIPTION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This package provides methods for validating whether objects and complex data |
108
|
|
|
|
|
|
|
structures conform to a schema. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This package has the following attributes: |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 definition |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
definition(HashRef $data) (HashRef) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The definition attribute is read-write, accepts C<(HashRef)> values, and is |
123
|
|
|
|
|
|
|
optional. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
I> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item definition example 1 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# given: synopsis |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
package main; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $definition = $schema->definition({}); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# {} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item definition example 2 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# given: synopsis |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# given: example-1 definition |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
package main; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$definition = $schema->definition; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# {} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 INHERITS |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This package inherits behaviors from: |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This package provides the following methods: |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 assert |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
assert() (Assert) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The assert method builds and returns a L object based on the |
178
|
|
|
|
|
|
|
L. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
I> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over 4 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item assert example 1 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# given: synopsis |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
package main; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my $assert = $schema->assert; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# bless({...}, 'Venus::Assert') |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=back |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=over 4 |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item assert example 2 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# given: synopsis |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
package main; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
$schema->definition({ |
205
|
|
|
|
|
|
|
name => 'string', |
206
|
|
|
|
|
|
|
}); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
my $assert = $schema->assert; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# bless({...}, 'Venus::Assert') |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 check |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
check(HashRef $data) (Bool) |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
The check method builds an assert object using L and returns the |
221
|
|
|
|
|
|
|
result of the L method. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
I> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=over 4 |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item check example 1 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# given: synopsis |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
package main; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
my $check = $schema->check; |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# 0 |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=back |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=over 4 |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item check example 2 |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# given: synopsis |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
package main; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
$schema->definition({ |
248
|
|
|
|
|
|
|
name => 'string', |
249
|
|
|
|
|
|
|
role => { |
250
|
|
|
|
|
|
|
title => 'string', |
251
|
|
|
|
|
|
|
level => 'number', |
252
|
|
|
|
|
|
|
}, |
253
|
|
|
|
|
|
|
}); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
my $check = $schema->check({}); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# 0 |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=back |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=over 4 |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item check example 3 |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# given: synopsis |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
package main; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
$schema->definition({ |
270
|
|
|
|
|
|
|
name => 'string', |
271
|
|
|
|
|
|
|
role => { |
272
|
|
|
|
|
|
|
title => 'string', |
273
|
|
|
|
|
|
|
level => 'number', |
274
|
|
|
|
|
|
|
}, |
275
|
|
|
|
|
|
|
}); |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
my $check = $schema->check({ |
278
|
|
|
|
|
|
|
name => 'someone', |
279
|
|
|
|
|
|
|
role => {}, |
280
|
|
|
|
|
|
|
}); |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
# 0 |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=back |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=over 4 |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=item check example 4 |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# given: synopsis |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
package main; |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
$schema->definition({ |
295
|
|
|
|
|
|
|
name => 'string', |
296
|
|
|
|
|
|
|
role => { |
297
|
|
|
|
|
|
|
title => 'string', |
298
|
|
|
|
|
|
|
level => 'number', |
299
|
|
|
|
|
|
|
}, |
300
|
|
|
|
|
|
|
}); |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
my $check = $schema->check({ |
303
|
|
|
|
|
|
|
name => 'someone', |
304
|
|
|
|
|
|
|
role => { |
305
|
|
|
|
|
|
|
title => 'engineer', |
306
|
|
|
|
|
|
|
level => 1, |
307
|
|
|
|
|
|
|
}, |
308
|
|
|
|
|
|
|
}); |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# 1 |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=back |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head2 deduce |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
deduce(HashRef $data) (Hash) |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
The deduce method builds an assert object using L and validates the |
321
|
|
|
|
|
|
|
value provided using L, passing the result to |
322
|
|
|
|
|
|
|
L unless the validation throws an exception. |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
I> |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=over 4 |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=item deduce example 1 |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
# given: synopsis |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
package main; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
my $deduce = $schema->deduce; |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=back |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=over 4 |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=item deduce example 2 |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
# given: synopsis |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
package main; |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
$schema->definition({ |
349
|
|
|
|
|
|
|
name => 'string', |
350
|
|
|
|
|
|
|
role => { |
351
|
|
|
|
|
|
|
title => 'string', |
352
|
|
|
|
|
|
|
level => 'number', |
353
|
|
|
|
|
|
|
}, |
354
|
|
|
|
|
|
|
}); |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
my $deduce = $schema->deduce({}); |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=back |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=over 4 |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=item deduce example 3 |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
# given: synopsis |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
package main; |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
$schema->definition({ |
371
|
|
|
|
|
|
|
name => 'string', |
372
|
|
|
|
|
|
|
role => { |
373
|
|
|
|
|
|
|
title => 'string', |
374
|
|
|
|
|
|
|
level => 'number', |
375
|
|
|
|
|
|
|
}, |
376
|
|
|
|
|
|
|
}); |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
my $deduce = $schema->deduce({ |
379
|
|
|
|
|
|
|
name => 'someone', |
380
|
|
|
|
|
|
|
role => {}, |
381
|
|
|
|
|
|
|
}); |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
=back |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=over 4 |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
=item deduce example 4 |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
# given: synopsis |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
package main; |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
$schema->definition({ |
396
|
|
|
|
|
|
|
name => 'string', |
397
|
|
|
|
|
|
|
role => { |
398
|
|
|
|
|
|
|
title => 'string', |
399
|
|
|
|
|
|
|
level => 'number', |
400
|
|
|
|
|
|
|
}, |
401
|
|
|
|
|
|
|
}); |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
my $deduce = $schema->deduce({ |
404
|
|
|
|
|
|
|
name => 'someone', |
405
|
|
|
|
|
|
|
role => { |
406
|
|
|
|
|
|
|
title => 'engineer', |
407
|
|
|
|
|
|
|
level => 1, |
408
|
|
|
|
|
|
|
}, |
409
|
|
|
|
|
|
|
}); |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
# bless({...}, 'Venus::Hash') |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
=back |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
=cut |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
=head2 error |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
error(HashRef $data) (Error) |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
The error method builds an assert object using L and validates the |
422
|
|
|
|
|
|
|
value provided using L, catching any error thrown and |
423
|
|
|
|
|
|
|
returning it, otherwise returning undefined. |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
I> |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=over 4 |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=item error example 1 |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
# given: synopsis |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
package main; |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
my $error = $schema->error; |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=back |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=over 4 |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
=item error example 2 |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
# given: synopsis |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
package main; |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
$schema->definition({ |
450
|
|
|
|
|
|
|
name => 'string', |
451
|
|
|
|
|
|
|
role => { |
452
|
|
|
|
|
|
|
title => 'string', |
453
|
|
|
|
|
|
|
level => 'number', |
454
|
|
|
|
|
|
|
}, |
455
|
|
|
|
|
|
|
}); |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
my $error = $schema->error({}); |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=back |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
=over 4 |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
=item error example 3 |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
# given: synopsis |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
package main; |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
$schema->definition({ |
472
|
|
|
|
|
|
|
name => 'string', |
473
|
|
|
|
|
|
|
role => { |
474
|
|
|
|
|
|
|
title => 'string', |
475
|
|
|
|
|
|
|
level => 'number', |
476
|
|
|
|
|
|
|
}, |
477
|
|
|
|
|
|
|
}); |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
my $error = $schema->error({ |
480
|
|
|
|
|
|
|
name => 'someone', |
481
|
|
|
|
|
|
|
role => {}, |
482
|
|
|
|
|
|
|
}); |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=back |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
=over 4 |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
=item error example 4 |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
# given: synopsis |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
package main; |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
$schema->definition({ |
497
|
|
|
|
|
|
|
name => 'string', |
498
|
|
|
|
|
|
|
role => { |
499
|
|
|
|
|
|
|
title => 'string', |
500
|
|
|
|
|
|
|
level => 'number', |
501
|
|
|
|
|
|
|
}, |
502
|
|
|
|
|
|
|
}); |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
my $error = $schema->error({ |
505
|
|
|
|
|
|
|
name => 'someone', |
506
|
|
|
|
|
|
|
role => { |
507
|
|
|
|
|
|
|
title => 'engineer', |
508
|
|
|
|
|
|
|
level => 1, |
509
|
|
|
|
|
|
|
}, |
510
|
|
|
|
|
|
|
}); |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
# undef |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=back |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=cut |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=head2 validate |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
validate(HashRef $data) (HashRef) |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
The validate method builds an assert object using L and validates the |
523
|
|
|
|
|
|
|
value provided using L, returning the result unless the |
524
|
|
|
|
|
|
|
validation throws an exception. |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
I> |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
=over 4 |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
=item validate example 1 |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
# given: synopsis |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
package main; |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
my $validate = $schema->validate; |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
=back |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=over 4 |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=item validate example 2 |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
# given: synopsis |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
package main; |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
$schema->definition({ |
551
|
|
|
|
|
|
|
name => 'string', |
552
|
|
|
|
|
|
|
role => { |
553
|
|
|
|
|
|
|
title => 'string', |
554
|
|
|
|
|
|
|
level => 'number', |
555
|
|
|
|
|
|
|
}, |
556
|
|
|
|
|
|
|
}); |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
my $validate = $schema->validate({}); |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=back |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
=over 4 |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
=item validate example 3 |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
# given: synopsis |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
package main; |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
$schema->definition({ |
573
|
|
|
|
|
|
|
name => 'string', |
574
|
|
|
|
|
|
|
role => { |
575
|
|
|
|
|
|
|
title => 'string', |
576
|
|
|
|
|
|
|
level => 'number', |
577
|
|
|
|
|
|
|
}, |
578
|
|
|
|
|
|
|
}); |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
my $validate = $schema->validate({ |
581
|
|
|
|
|
|
|
name => 'someone', |
582
|
|
|
|
|
|
|
role => {}, |
583
|
|
|
|
|
|
|
}); |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
# Exception! (isa Venus::Assert::Error) |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=back |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=over 4 |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=item validate example 4 |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
# given: synopsis |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
package main; |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
$schema->definition({ |
598
|
|
|
|
|
|
|
name => 'string', |
599
|
|
|
|
|
|
|
role => { |
600
|
|
|
|
|
|
|
title => 'string', |
601
|
|
|
|
|
|
|
level => 'number', |
602
|
|
|
|
|
|
|
}, |
603
|
|
|
|
|
|
|
}); |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
my $validate = $schema->validate({ |
606
|
|
|
|
|
|
|
name => 'someone', |
607
|
|
|
|
|
|
|
role => { |
608
|
|
|
|
|
|
|
title => 'engineer', |
609
|
|
|
|
|
|
|
level => 1, |
610
|
|
|
|
|
|
|
}, |
611
|
|
|
|
|
|
|
}); |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
# {name => 'someone', role => {title => 'engineer', level => 1,},} |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
=back |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
=cut |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=head1 AUTHORS |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
Awncorp, C |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
=cut |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=head1 LICENSE |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
Copyright (C) 2000, Al Newkirk. |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
630
|
|
|
|
|
|
|
the terms of the Apache license version 2.0. |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=cut |