Thanks for the comments. $_ is corrected (my mistake) and (1) was there because I wanted to write about this line, as it should print "Scalar expected, reference found on position $index." when called normally, and "Scalar expected, reference found on position $index in row $row." when called from &is_array_of_array_of_scalar(). Just problem of finding context.
Structures will grow and AoA will be part of another bigger one, so simple grep won't be enough.
I tried exceptions mechanism, but I think It has no use here - there is no way to handle exceptions outside validation functions. I decided just to use warn "in cascades", so I get info message like this:
V::is_array_of_scalar: Scalar expected, HASH reference found on positi +on 2. Input: $VAR1 = [ 'abc', 'def', { 'some' => 'any' }, 'x', 'something' ]; V::is_array_of_array_of_scalar: Wrong value(s) in row 1. at scripts/li +b/V.pm line 102. input argument of [FDFr::compareArr] for key '-elem2' fails its contra +ct constraint at (eval 12) line 31
but it will be pretty unreadable as V module will grow. So finally your hint about passing additional argument seems to be the best solution. If the function is called as top-level validator (no possibility to pass additional arguments), it will just print its error message, but if is called by other validation function, passing arguments is possible to pass any arguments and change messages. Thanks for ideas, I'm going back to work :)
In reply to Re^2: proper Sub::Contract use
by Anonymous Monk
in thread proper Sub::Contract use
by grizzley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |