How does Perl 6 evaluate truthiness?

Perl 6 evaluates truth now by asking the object a question instead of looking at its value. The value is not the object. It's something I've liked about other object languages and will be glad to have in Perl: I get to decide how the object responds and can mutate that. As ysth said, you could do that in Perl 5 with overload, but I always feel like I have to wash my hands after doing it that way. :)

If you don't do anything to change that, Perl 6 behaves in the same way as Perl 5 so you get the least amount of surprise.


Truthness test just calls the .true method on an object, so the "mix in" operation $stuff but True just (among other things) overrides that method.

This is specified in S02, generally enum types (of which Bool is one) are described in S12.


See Synopsis 12: Roles.

The rules are the same, but the "but" copies the 0 and applies a role to the copy that causes it to be true in boolean context.

You can do the same thing with overload in Perl 5.