Subject: | Inconsistent use of on_fail in PP and XS versions |
In general, the module rocks. However, the documentation implies either
the user defined on_fail() callback or Carp::confess() will be used. In
the Params::ValidatePP code it is a case of one or the other. However,
in Params::ValidateXS, both user defined on_fail() and Carp's confess()
are called.
I want to accumulate all the validation errors and generate a single
report[1]. Even if I catch the exception thrown by confess(), validation
is interrupted so I can only capture the first error.
There are two workarounds, both ugly.
First, I can force Params::ValidatePP to be used due to improper insight
into how Params::Validate decides which underlying module to load. That
looks like:
BEGIN {
$ENV{PV_TEST_PERL} = 1;
}
use Params::Validate qw(:all);
The second workaround is to recklessly redefine Carp::confess() to be a
no-op. A sample of doing that is:
{
no warnings 'redefine';
use Carp;
sub Carp::confess { }
}
Like I said, both workarounds are ugly. I request that the XS logic be
changed to match the documentation; namely that parameter validation
proceeds onward without a call to confess(). Yes, that could lead to
unpredictable results. But if the user is providing on_fail() without a
call to die() in the first place, it is reasonable to expect them to
subsequently test for failures.
[1] Fyi, I am validating user provided data. IMHO users are annoyed if
the program doles out one error at a time and forces them to rerun the
program each time. It is much better to notify them of all errors at once.