develooper Front page | perl.moose | Postings from June 2011

Moose Type Constraints violations to warnings?

Thread Next
June 10, 2011 03:06
Moose Type Constraints violations to warnings?
Message ID:
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?

Backstory for those who care: we're actually using Mouse instead of Moose and the company may decide to eliminate Mouse. Currently the odds of upgrading to Moose are roughly zero (not my decision), so if there's a solution using Moose but it does not work with Mouse, we may just have Mouse eliminated entirely and not get Moose, either (long story).

So if we have a hotel whose "short description" is missing or longer than 200 characters, we can live with that, but we can't live with an invalid price. We're happy to clean up bad information but we don't want type constraints to throw out *everything* just because someone goofed (often an external data source we have little control over). Part of the reason management is very unhappy with our use of Mouse is because of these type constraints causing application failure we've never had in the past. We much prefer to bend rather than break.


Live and work overseas -
Buy the book           -
Tech blog              -
Twitter                -
Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About