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