Subject: | ValidateXS errors when on_fail doesn't die; ValidatePP works great |
I've tested this using Perl 5.6.1 and 5.8.0.
For user interface purposes, I wanted Params::Validate to check all of the arguments and report all of the errors so I could properly report back to the user which fields were filled out erroneously. The documentation implied that, if I supplied an 'on_fail' code reference that didn't die, Params::Validate would validate all of the arguments. Wonderfull. So I created a exceptions container class and a validate_all wrapper which calls validate_with with an 'on_fail' code reference that adds each error to my exceptions container class. After the call to validate_with, the exception is thrown if the container is not empty. Everything works great with ValidatePP, but it just doesn't work at all with ValidateXS. With ValidateXS, you get the following error:
Can't use an undefined value as a HASH reference at (eval 1) line 78.
And I believe that is line 78 in ValidateXS.pm. I thought I'd try it with ValidatePP by setting the appropriate environment variable, and it worked! ValidateXS and ValidatePP should give identical results, I think.
I could come up with some code which shows this, but it should be easy enough to test. Addin the following argument to any validate_with call should do it: 'on_fail' => sub { print "$_[0]\n"; }