« blib/lib/Valiemon/Attributes/AdditionalItems.pm
↑ Summary
blib/lib/Valiemon/Attributes/MaxProperties.pm »
| 1 | package Valiemon::Attributes::Required; | ||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use parent qw(Valiemon::Attributes); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use List::MoreUtils qw(all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 66 | ▶ | sub attr_name { 'required' } | ||||||||||||||||||||||||||
|
Subroutine
attr_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub is_valid { | ||||||||||||||||||||||||||||
| 13 | 78 | ▶ | my ($class, $context, $schema, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 78 | ▶ | return 1 unless ref $data eq 'HASH'; # ignore | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 66 | my $required = $schema->{required}; | |||||||||||||||||||||||||||
| 18 | $context->in_attr($class, sub { | ||||||||||||||||||||||||||||
| 19 | 66 | ▶ | if (ref $required ne 'ARRAY' || scalar @$required < 1) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%3/3
ref $required ne "ARRAY" or scalar @$required < 1
MC/DC100%2/2
ref $required ne "ARRAY" or scalar @$required < 1
ref $required ne "ARRAY"
scalar @$required < 1
Truth table100%3/3
A or B
A= ref $required ne "ARRAY"B= scalar @$required < 1
| |||||||||||||||||||||||||||||
| 20 | 2 | croak sprintf '`required` must be an array and have at leas one element at %s', $context->position | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | all { | ||||||||||||||||||||||||||||
| 23 | 84 | ▶ | my $prop_def = $schema->{properties}->{$_}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 24 | 84 | ▶ | my $has_default = $prop_def && do { | ||||||||||||||||||||||||||
|
Condition100%3/3
$prop_def && do {
my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def;
$definition->{'default'}
}
MC/DC100%2/2
$prop_def && do {
my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def;
$definition->{'default'}
}
$prop_def
do {
my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def;
$definition->{'default'}
}
Truth table100%3/3
A && B
A= $prop_defB= do {
my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def;
$definition->{'default'}
}
| |||||||||||||||||||||||||||||
| 25 | # resolve $ref TODO refactor | ||||||||||||||||||||||||||||
| 26 | 73 | ▶ | my $definition = $prop_def->{'$ref'} ? $context->rv->resolve_ref($prop_def->{'$ref'}) : $prop_def; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 73 | $definition->{default}; | |||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | 84 | ▶ | $has_default || exists $data->{$_} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 64 | } @$required; | |||||||||||||||||||||||||||
| 31 | 66 | }); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 10 | 1; | |||||||||||||||||||||||||||