Subject: | Subtle change to constraint checks for Bool would help JSON parsing |
The check for Bool at: ll. 714 of Moose::Util::TypeConstraints
could be helpfully altered:
713 subtype 'Bool' => as 'Item' =>
714 where { !defined($_) || $_ eq "" || "$_" eq '1' || "$_" eq '0' };
When parsing JSON parsed by the standard JSON module against Moose types, the JSON::PP::Boolean objects evaluate false against this test, due to stringification which
produces "true" and "false". They do pass the test if the type is changed to:
713 subtype 'Bool' => as 'Item' =>
714 where { !defined($_) || $_ eq '1' || $_ eq '0' || "$_" eq '1'|| "$_" eq '0' || $_ eq "" };
Which adds unstringified tests in there as well. While I am perfectly sure you have good reasons for the choice of quoted "$_", this subtle change would make little
things like this much easier. This doesn't mean any specific logic for this one class, and probably solves problems for a number of overloaded objects out there.
You might wonder why not just try with a coercion? Well, the stringification, combined with overloaded "eq" produced noisy warnings during the check() which coercion
cannot silence. It is perfectly possible to coerce, but there should be no need to, as in every practical sense these objects behave boolishly (if that is a word).
If the test is reordered to postpone that test, the