So I haven't looked at the branch yet, but the idea sounds sane to me. I believe we have an equivalent concept for the type checking too.

- Stevan


On Oct 22, 2010, at 8:05 PM, Ricardo Signes wrote:


I'd really like to do this a lot:

 sub whatever {
   my ($self, $input) = @_;
   $input = to_SomeType($input);

   ...
 }

...but this is not useful because to_SomeType returns false on failure to coerce. Similarly, $type->coerce($input) returns $input on failure to coerce.

Some time ago I added $type->assert_valid and found that to be an excellent addition. This is a similar method, assert_coerce, that will either return a
valid value in the given type or will throw an exception.

The code is in rfc/assert_coerce, and I am giving it a +1 for merging as a
small, useful method built entirely in terms of existing features.

--
rjbs

Reply via email to