Subject: | Dependencies and required fields |
In the code that checks the dependencies hash for optional fields that should become
required, there is a bug that means the dependent field does not become required if the field
upon which is depends has more than one value.
e.g. if the dependencies hash looks like this:
dependencies => {
# if pay_type eq 'check', require check_no
pay_type => {
check => [ qw( check_no ) ],
}
},
and I have two (perfectly valid) values for pay_type, 'check_no' will not be added to the list of
required fields.
The problem is in the D::FV::Results code preceded by the comment
" # Handle case of a key with a single value given as an arrayref
# There is probably a better, more general solution to this problem."
(~ line 225)
I fixed it using the following code:
for my $key (keys %$deps) { # line 224
# Handle case of a key with a single value given as an arrayref
# There is probably a better, more general solution to this problem.
my $val_to_compare;
if (ref $valid{$field} eq 'ARRAY')
{ $val_to_compare = $valid{$field};
}
else {
$val_to_compare = [ $valid{$field} ];
}
if (grep { $key } @$val_to_compare){
for my $dep (_arrayify($deps->{$key})){
$required{$dep} = 1;
}
}
}