line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Properties; |
2
|
12
|
|
|
12
|
|
5102
|
use strict; |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
286
|
|
3
|
12
|
|
|
12
|
|
38
|
use warnings; |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
222
|
|
4
|
12
|
|
|
12
|
|
33
|
use utf8; |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
42
|
|
5
|
12
|
|
|
12
|
|
586
|
use parent qw(Valiemon::Attributes); |
|
12
|
|
|
|
|
253
|
|
|
12
|
|
|
|
|
61
|
|
6
|
|
|
|
|
|
|
|
7
|
12
|
|
|
12
|
|
520
|
use Carp qw(croak); |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
481
|
|
8
|
12
|
|
|
12
|
|
43
|
use Clone qw(clone); |
|
12
|
|
|
|
|
40
|
|
|
12
|
|
|
|
|
432
|
|
9
|
12
|
|
|
12
|
|
459
|
use List::MoreUtils qw(all); |
|
12
|
|
|
|
|
7688
|
|
|
12
|
|
|
|
|
57
|
|
10
|
12
|
|
|
12
|
|
3243
|
use Valiemon; |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
2913
|
|
11
|
|
|
|
|
|
|
|
12
|
184
|
|
|
184
|
0
|
331
|
sub attr_name { 'properties' } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_valid { |
15
|
184
|
|
|
184
|
0
|
218
|
my ($class, $context, $schema, $data) = @_; |
16
|
|
|
|
|
|
|
$context->in_attr($class, sub { |
17
|
184
|
100
|
|
184
|
|
402
|
return 1 unless ref $data eq 'HASH'; # ignore |
18
|
|
|
|
|
|
|
|
19
|
178
|
|
|
|
|
193
|
my $properties = $schema->{properties}; |
20
|
178
|
50
|
|
|
|
273
|
unless (ref $properties eq 'HASH') { |
21
|
0
|
|
|
|
|
0
|
croak sprintf '`properties` must be an object at %s', $context->position |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
178
|
|
|
|
|
139
|
my $is_valid = 1; |
25
|
178
|
|
|
|
|
330
|
for my $prop (keys %$properties) { |
26
|
255
|
100
|
|
|
|
401
|
unless (exists $data->{$prop}) { |
27
|
|
|
|
|
|
|
my $definition = $properties->{$prop}->{'$ref'} # resolve ref TODO refactor |
28
|
|
|
|
|
|
|
? $context->rv->resolve_ref($properties->{$prop}->{'$ref'}) |
29
|
74
|
100
|
|
|
|
130
|
: $properties->{$prop}; |
30
|
73
|
100
|
|
|
|
183
|
if (my $default = $definition->{default}) { |
|
|
100
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# fill in default |
32
|
6
|
|
|
|
|
43
|
$data->{$prop} = clone($default); |
33
|
|
|
|
|
|
|
# in case default value applied, skip validation for default value |
34
|
6
|
|
|
|
|
11
|
next; |
35
|
|
|
|
|
|
|
} elsif ($definition->{required}) { |
36
|
|
|
|
|
|
|
# if required specified and default not exists, it's invalid |
37
|
|
|
|
|
|
|
# TODO check definition. Is it valid existing "default" and "required" in same property??? |
38
|
5
|
|
|
|
|
18
|
$is_valid=0; |
39
|
5
|
|
|
|
|
8
|
last; |
40
|
|
|
|
|
|
|
} else { |
41
|
62
|
|
|
|
|
86
|
next; # skip on no-required empty |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
181
|
|
|
|
|
157
|
my $sub_data = $data->{$prop}; |
46
|
181
|
|
|
|
|
137
|
my $sub_schema = $properties->{$prop}; |
47
|
|
|
|
|
|
|
my $res = $context->in($prop, sub { |
48
|
181
|
|
|
|
|
294
|
$context->sub_validator($sub_schema)->validate($sub_data, $context); |
49
|
181
|
|
|
|
|
564
|
}); |
50
|
|
|
|
|
|
|
|
51
|
179
|
100
|
|
|
|
548
|
if (!$res) { |
52
|
43
|
|
|
|
|
40
|
$is_valid = 0; |
53
|
43
|
|
|
|
|
53
|
last; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
175
|
|
|
|
|
240
|
$is_valid; |
58
|
184
|
|
|
|
|
775
|
}); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |