On Fri, Jun 10, 2011 at 1:14 PM, Buddy Burden <barefootcoder@gmail.com> wrote: > Ovid, > > On Fri, Jun 10, 2011 at 3:06 AM, Ovid <publiustemp-catalyst@yahoo.com> wrote: >> When I declare a parameter as follows: >> >> >> has 'some_val' => ( >> is => 'rw', >> isa => 'Int', >> ); >> >> Later if I do $object->some_value("foobar"), it blows up with a stack trace because of the type constraint violation. >> >> Without using signal handlers, is there some way I can convert that exception into a warning except when something like $ENV{HARNESS_ACTIVE} is true? Preferably on a per-attribute basis? > > Is it possible that Jesse's answer to my question here: > > http://www.mail-archive.com/moose@perl.org/msg01464.html > > could help? I know it isn't exactly the same problem that you're > describing, but it seems that if there's a way to solve one, there > must be a way to solve the other as well. Possibly the code of the > module he mentions would be illuminating. > > Apologies if this isn't actually helpful. Karen also suggested MooseX::Constructor::AllErrors but discarded it because it was Moose only. A Mouse port would probably be pretty simple. But it only covers the constructor case. For accessors, if the issue is that you "don't want type constraints to throw out *everything*" you'll need to show a better example of the parsing code because I'm not sure how a judicious use of Try::Tiny wouldn't be the natural solution there. Accessors never really operate on the entire object, so you'd only throw an exception for a specific attribute. Wrapping the block in Try::Tiny will leave the object in a partial state (whatever had been mutated until the exception was thrown) and give you an error message you could then dispatch with. The particular phrase Ovid referred to in the Moose docs was written a *long* time ago when Stevan still believed that you could potentially safely turn off runtime type checks. My impression is that he's re-considered this idea now. It also applies to Moose and not Mouse. Mouse has it's own development community and goals. -ChrisThread Previous | Thread Next