Moosites,
This is a request from a co-worker; I'll see if I can explain it well.
Let's say I have a simple Moose class:
use Company::Moose; # this module gets me MooseX::Declare, and also
declares all my class types, like the one I'm using below
class Foo
{
has 'bar' => ( is => 'ro', isa => Int);
has 'baz' => ( is => 'ro', isa => Company::Thingy );
};
So now if I later do this:
my $foo = Foo->new(bar => "I'm not an int!", baz =>
Company::DifferentThingy->new );
then my code will fail with a run-time error. Which is generally what I want.
But suppose I want to collect these validation errors and return them
in some more useful fashion? I could always wrap my call to new() in
an eval, of course, but then I'd have to parse the "internal
validation error" out of $@, which seems yucky. Basically what I want
is to return some list of errors back to my caller, perhaps a web
page, saying "bar wasn't an integer, and baz wasn't a Thingy" so that
then my caller can hopefully do something about that (e.g. notify the
user that their input was invalid). Is there some trickery I can do
with BUILD or BUILDARGS or somesuch to achieve this fairly easily?
TIA for any help.
-- Buddy