Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 127090
Status: rejected
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: SLOYD [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.004002
Fixed in: (no value)



Subject: Bool type check fails on JSON::PP::Boolean
With version 1.004002, use 5.010; use Types::Standard qw(Bool); use JSON::MaybeXS; say Bool->check(JSON()->true); # prints nothing But with older Type-Tiny versions like 1.002001 (that's what's available to me below 1.004002), above would print 1, which makes sense I think.
The Bool check was implemented inconsistently between Type::Tiny, Type::Tiny::XS, Moose, and Mouse. Additionally the Moose documentation possibly implies different behaviour to its implementation. As of Types::Standard 1.004000 and Type::Tiny::XS 0.014, Bool accepts the following four values and no others: "" "0" "1" undef You can use coerce=>1 to accept other values and coerce it to an acceptable value. The behaviour of Mouse (and older versions of Type::Tiny::XS which is based on Mouse's type checking code) was to accept objects overloading boolification BUT ONLY FOR FALSE, NOT FOR TRUE! The behaviour of Moose (and older versions of Types::Standard) was to accept objects overloading STRINGIFICATION (not boolification!) to return one of the allowed string values. Mouse's behaviour of only accepting overloaded objects if they returned false was clearly stupid. Moose's behaviour of accepting overloaded objects but using their string overload instead of boolean overload is also fairly stupid. So I decided to stick strictly to what Moose::Manual::Types says: Show quoted text
> "Bool" accepts 1 for true, and undef, 0, > or the empty string as false.
Other values, including overloaded objects, now fail the constraint. If you set coerce=>1, then you can accept any value, and it will be coerced like !!$value, yielding a simple boolean. An alternative, if you don't want to do coercion would be something like: isa => Bool | InstanceOf['JSON::PP::Boolean'] or more generally: isa => Bool | Overload["bool"] or a little faster if you trust your user not to send stupid objects which make no sense: isa => Bool | Object or even faster if you just don't care: isa => Any But anyway, this change was deliberate and is documented, so rejecting this issue.