Subject: | Reduce boilerplate for message |
The message example in the docs demonstrates the value of using the "most general" constraint as the message:
declare EvenInt,
as Int,
where { $_ % 2 == 0 },
message {
if (Int->check($_))
{ "$_ is an integer, but not even" }
else
{ "$_ is not an integer" }
};
but that approach rapidly gets unwieldy with deeper hierarchies of types (Int -> Int2 -> Int2_not_negative etc)
Firstly, are there any problems with rewriting that as:
message {
return Int->get_message($_) unless Int->check($_);
"$_ is an integer, but not even";
};
which seems much cleaner.
And secondly, could Type::Tiny do that for me? Perhaps optionally, but default on as it seems most people would want that.