4. Boolean in Perl 5 is not
that simple
Because we don't have native boolean
5. Typical implementation of
boolean in Perl 5
my $true = 1;
my $false = 0;
$T = bless $true, $boolean_class;
$F = bless $false, $boolean_class;
(with some overload configuration)
6. What if a "boolean" object
is embedded in a string?
• use overload to convert them into
"true" or "false"?
• ... if "$false"; # but true
• say "This is " .
($bool->isa($boolean_class)
? ($bool ? "true" : "false")
: $bool); # ugly
7. How can you tell if
it's a boolean?
• MetaCPAN returns 1877 results
when you search "Bool"...
• Not all of them represent
boolean, though...
8. Don't worry too much
All of them should work in
the Perl context, at least
as long as you use them in
the boolean context
9. Until you start
serializing your data
JSON modules only accept
JSON::PP::Boolean objects
(or their aliases) by default
10. Luckily JSON::PP::Boolean
is in Perl 5 core now
• You can use it as a default
boolean class
• Do you want to use JSON::PP
just to get boolean objects?
11. How about boolean.pm?
• It would have been nice if it were
more widely adopted
• Unfortunately it is not supported
by JSON modules by default
12. Or Types::Serialiser?
• It provides boolean objects that are
JSON::PP::Boolean
• It has a more neutral name for CBOR::XS
• It's not in core, so it's hard to adopt for
toolchain modules or the likes
13. Then what to do?
• Add something into core?
• Or just use the same
convention under the hood?
• Or else?
14. The bottomline
• The new stuff should work
with existing modules
• Otherwise you can't use it
for interoperability
16. bool.pm
• Written by Tina Mueller as a
proof of concept at PTS 2018
• Not yet CPANized
https://github.com/perlpunk/bool-p5/tree/json-pp-compat
17. Types::Bool
• Written by Adriano Ferreira,
inspired by Tina's PTS report
• Works quite similar to
Types::Serialiser
https://metacpan.org/pod/Types::Bool
18. There are still issues
to be solved
• bool namespace and Perl 6?
• Types:: namespace is reserved
for a different purpose?
• duplicated effort?
• and probably more
19. Further reading
• "My report of the Perl Toolchain Summit
2018 in Oslo" by Tina Mueller
http://blogs.perl.org/users/tinita/2018/05/my-report-of-the-
perl-toolchain-summit-2018-in-oslo.html
• "[Work in Progress] Boolean support with
Types::Bool"
https://github.com/makamaka/JSON-PP/pull/36