[Dbix-class] DBIx::Class::Validation - croak's With The Validation
Result..?
Peter Rabbitson
rabbit+dbic at rabbit.us
Wed Feb 9 07:40:56 GMT 2011
Skye Shaw wrote:
> Hi,
>
> Does anyone find it odd that DBIx::Class::Validation croaks when
> validation fails via $obj->validate?
>
> I understand the need to do this on insert & update, but it seems a
> little unorthodox writing code like the following just to check the
> validation result:
>
> my $result;
> eval { $result = $obj->validate };
> $result = $@ if $@;
>
> This can become (more) cumbersome if the validation involves querying the DB.
This is why you write:
try {
my $good_result = $obj->validate;
do stuff with good result
} catch {
my $bad_result = $_
do stuff with bad result
};
Or if you "do stuff" the same:
my $result = try { $obj->validate } catch { $_ };
Exception based control flow is very common and very useful. You can't ignore
it or forget about it unlike the pesky:
return $ok ? ($ok_ret) : (undef, $fail_ret)
More information about the DBIx-Class
mailing list