line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Required; |
2
|
10
|
|
|
10
|
|
4327
|
use strict; |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
239
|
|
3
|
10
|
|
|
10
|
|
32
|
use warnings; |
|
10
|
|
|
|
|
8
|
|
|
10
|
|
|
|
|
185
|
|
4
|
10
|
|
|
10
|
|
28
|
use utf8; |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
39
|
|
5
|
10
|
|
|
10
|
|
917
|
use parent qw(Valiemon::Attributes); |
|
10
|
|
|
|
|
513
|
|
|
10
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
440
|
use Carp qw(croak); |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
406
|
|
8
|
10
|
|
|
10
|
|
869
|
use List::MoreUtils qw(all); |
|
10
|
|
|
|
|
14825
|
|
|
10
|
|
|
|
|
78
|
|
9
|
|
|
|
|
|
|
|
10
|
66
|
|
|
66
|
0
|
115
|
sub attr_name { 'required' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_valid { |
13
|
78
|
|
|
78
|
0
|
92
|
my ($class, $context, $schema, $data) = @_; |
14
|
|
|
|
|
|
|
|
15
|
78
|
100
|
|
|
|
155
|
return 1 unless ref $data eq 'HASH'; # ignore |
16
|
|
|
|
|
|
|
|
17
|
66
|
|
|
|
|
73
|
my $required = $schema->{required}; |
18
|
|
|
|
|
|
|
$context->in_attr($class, sub { |
19
|
66
|
100
|
100
|
66
|
|
281
|
if (ref $required ne 'ARRAY' || scalar @$required < 1) { |
20
|
2
|
|
|
|
|
5
|
croak sprintf '`required` must be an array and have at leas one element at %s', $context->position |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
all { |
23
|
84
|
|
|
|
|
104
|
my $prop_def = $schema->{properties}->{$_}; |
24
|
84
|
|
66
|
|
|
139
|
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
|
84
|
100
|
|
|
|
253
|
$has_default || exists $data->{$_} |
30
|
64
|
|
|
|
|
282
|
} @$required; |
31
|
66
|
|
|
|
|
255
|
}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |