line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Required; |
2
|
10
|
|
|
10
|
|
6158
|
use strict; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
339
|
|
3
|
10
|
|
|
10
|
|
53
|
use warnings; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
239
|
|
4
|
10
|
|
|
10
|
|
49
|
use utf8; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
57
|
|
5
|
10
|
|
|
10
|
|
735
|
use parent qw(Valiemon::Attributes); |
|
10
|
|
|
|
|
327
|
|
|
10
|
|
|
|
|
51
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
696
|
use Carp qw(croak); |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
576
|
|
8
|
10
|
|
|
10
|
|
598
|
use List::MoreUtils qw(all); |
|
10
|
|
|
|
|
12166
|
|
|
10
|
|
|
|
|
72
|
|
9
|
|
|
|
|
|
|
|
10
|
67
|
|
|
67
|
0
|
211
|
sub attr_name { 'required' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_valid { |
13
|
79
|
|
|
79
|
0
|
188
|
my ($class, $context, $schema, $data) = @_; |
14
|
|
|
|
|
|
|
|
15
|
79
|
100
|
|
|
|
232
|
return 1 unless ref $data eq 'HASH'; # ignore |
16
|
|
|
|
|
|
|
|
17
|
67
|
|
|
|
|
176
|
my $required = $schema->{required}; |
18
|
|
|
|
|
|
|
$context->in_attr($class, sub { |
19
|
67
|
100
|
100
|
67
|
|
379
|
if (ref $required ne 'ARRAY' || scalar @$required < 1) { |
20
|
2
|
|
|
|
|
7
|
croak sprintf '`required` must be an array and have at leas one element at %s', $context->position |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
all { |
23
|
85
|
|
|
|
|
180
|
my $prop_def = $schema->{properties}->{$_}; |
24
|
85
|
|
100
|
|
|
210
|
my $has_default = $prop_def && do { |
25
|
|
|
|
|
|
|
# resolve $ref TODO refactor |
26
|
|
|
|
|
|
|
my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def; |
27
|
|
|
|
|
|
|
$definition->{default}; |
28
|
|
|
|
|
|
|
}; |
29
|
85
|
100
|
|
|
|
373
|
$has_default || exists $data->{$_} |
30
|
65
|
|
|
|
|
324
|
} @$required; |
31
|
67
|
|
|
|
|
454
|
}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |