DBIx::Class::Validation Gotcha!

DBIxClassValidation is a validation library for [DBIxClass](https://metacpan.org/pod/DBIxClass) objects to enable in-model validation.

When validating an object, however, DBIxClassValidation uses croak to raise an exception if there are any invalid or missing values. This makes all the validation code look a little funky:

eval { $model->validate() };
if (my $result = $@) { ... }

Here’s the kicker, though. If the validation succeeds, the $result variable does not exist. “So what?”, I hear you say. Imagine writing a web form for this. You cannot get a valid $result unless errors are present, so you cannot, for example, send a passing $result to the form template. Now you need two different forms, one with $result and one without. 🤢


Yeah, the title is a bit click-bait-y. This isn’t really a “gotcha” (it is right there in the docs, after all).