line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Properties; |
2
|
8
|
|
|
8
|
|
5990
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
306
|
|
3
|
8
|
|
|
8
|
|
42
|
use warnings; |
|
8
|
|
|
|
|
54
|
|
|
8
|
|
|
|
|
277
|
|
4
|
8
|
|
|
8
|
|
39
|
use utf8; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
53
|
|
5
|
8
|
|
|
8
|
|
700
|
use parent qw(Valiemon::Attributes); |
|
8
|
|
|
|
|
240
|
|
|
8
|
|
|
|
|
52
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
605
|
use Carp qw(croak); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
589
|
|
8
|
8
|
|
|
8
|
|
5192
|
use Clone qw(clone); |
|
8
|
|
|
|
|
26656
|
|
|
8
|
|
|
|
|
702
|
|
9
|
8
|
|
|
8
|
|
552
|
use List::MoreUtils qw(all); |
|
8
|
|
|
|
|
9171
|
|
|
8
|
|
|
|
|
90
|
|
10
|
8
|
|
|
8
|
|
3961
|
use Valiemon; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
2870
|
|
11
|
|
|
|
|
|
|
|
12
|
53
|
|
|
53
|
0
|
181
|
sub attr_name { 'properties' } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_valid { |
15
|
53
|
|
|
53
|
0
|
113
|
my ($class, $context, $schema, $data) = @_; |
16
|
|
|
|
|
|
|
$context->in_attr($class, sub { |
17
|
53
|
100
|
|
53
|
|
202
|
return 1 unless ref $data eq 'HASH'; # ignore |
18
|
|
|
|
|
|
|
|
19
|
52
|
|
|
|
|
89
|
my $properties = $schema->{properties}; |
20
|
52
|
50
|
|
|
|
185
|
unless (ref $properties eq 'HASH') { |
21
|
0
|
|
|
|
|
0
|
croak sprintf '`properties` must be an object at %s', $context->position |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
52
|
|
|
|
|
65
|
my $is_valid = 1; |
25
|
52
|
|
|
|
|
187
|
for my $prop (keys %$properties) { |
26
|
83
|
100
|
|
|
|
210
|
unless (exists $data->{$prop}) { |
27
|
|
|
|
|
|
|
# fill in default |
28
|
6
|
|
|
|
|
16
|
my $default = do { |
29
|
|
|
|
|
|
|
my $definition = $properties->{$prop}->{'$ref'} # resolve ref TODO refactor |
30
|
|
|
|
|
|
|
? $context->rv->resolve_ref($properties->{$prop}->{'$ref'}) |
31
|
6
|
100
|
|
|
|
36
|
: $properties->{$prop}; |
32
|
6
|
|
|
|
|
17
|
$definition->{default}; |
33
|
|
|
|
|
|
|
}; |
34
|
6
|
100
|
|
|
|
27
|
if ($default) { |
35
|
2
|
|
|
|
|
15
|
$data->{$prop} = clone($default); |
36
|
|
|
|
|
|
|
} |
37
|
6
|
|
|
|
|
20
|
next; # skip |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
77
|
|
|
|
|
123
|
my $sub_data = $data->{$prop}; |
41
|
77
|
|
|
|
|
106
|
my $sub_schema = $properties->{$prop}; |
42
|
|
|
|
|
|
|
my $res = $context->in($prop, sub { |
43
|
77
|
|
|
|
|
216
|
$context->sub_validator($sub_schema)->validate($sub_data, $context); |
44
|
77
|
|
|
|
|
497
|
}); |
45
|
|
|
|
|
|
|
|
46
|
77
|
100
|
|
|
|
373
|
if (!$res) { |
47
|
19
|
|
|
|
|
30
|
$is_valid = 0; |
48
|
19
|
|
|
|
|
41
|
last; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
52
|
|
|
|
|
134
|
$is_valid; |
53
|
53
|
|
|
|
|
473
|
}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |