June 2018 Archives

What is a Bool?

Perl allows pretty much any value to be evaluated in a boolean context:

if ($something) {
   ...
}

No matter what $something is, it will safely evaluate to either true or false. (With the exceptions of a few edge cases like blessed objects which are overloaded to throw an error when evaluated as booleans.)

So when a Moose class does something like this, what does it mean?

has something => (
   is  => 'ro',
   isa => 'Bool',
);

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.