Moose::...it::Bool(3)

✨ Moose::Meta::Attribute::Native::Trait::Bool β€” the helper trait for Bool attributes ✨

okay bestie, welcome to the Moose::...it::Bool(3) page (yes that's the shortened name, the full one is Moose::Meta::Attribute::Native::Trait::Bool and it's a whole mouthful, we don't gatekeep) πŸ’–


πŸ’« VERSION

version 2.4000 β€” she's serving, she's current, she's iconic πŸŽ€


🌸 SYNOPSIS

okay so picture this: you want a boolean attribute but you also want cute little named methods for flipping it around. say less:

package Room;
use Moose;

has 'is_lit' => (
    traits  => ['Bool'],
    is      => 'rw',
    isa     => 'Bool',
    default => 0,
    handles => {
        illuminate  => 'set',
        darken      => 'unset',
        flip_switch => 'toggle',
        is_dark     => 'not',
    },
);

my $room = Room->new();
$room->illuminate;        # same as $room->is_lit(1);
$room->darken;            # same as $room->is_lit(0);
$room->flip_switch;       # same as $room->is_lit(not $room->is_lit);
return $room->is_dark;    # same as !$room->is_lit

like. the way flip_switch is just right there doing the most. obsessed πŸ’…


πŸ¦‹ DESCRIPTION

This trait hands you native delegation methods for boolean values, no cap. And a boolean, for the record, is a scalar that can be 1, 0, "", or "undef". that's the whole vibe check. βœ…


⭐ DEFAULT TYPE

If you don't hand over an isa value for your attribute, it just defaults to Bool. she's lowkey self-sufficient like that πŸ™ˆ


πŸ‘‘ PROVIDED METHODS

Real talk: none of these methods accept arguments. not a single one. they take zero input and they deliver.

  • set β€” sets the value to 1 and returns 1. simple, clean, ate.
  • unset β€” sets the value to 0 and returns 0. the opposite queen.
  • toggle β€” toggles the value: if it's true, it sets it to false, and vice versa. and she returns the new value, because she's generous.
  • not β€” the equivalent of not $value. that's it, that's the whole thing. fr fr.

πŸ’€ BUGS

Want the tea on reporting bugs? See "BUGS" in Moose for all the details. go off, file that report 🫢


🌈 AUTHORS

these are the legends who made this happen, show some respect:

  • Stevan Little <stevan@cpan.org>
  • Dave Rolsky <autarch@urth.org>
  • Jesse Luehrs <doy@cpan.org>
  • Shawn M Moore <sartak@cpan.org>
  • Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) <nothingmuch@woobling.org>
  • Karen Etheridge <ether@cpan.org>
  • Florian Ragwitz <rafl@debian.org>
  • Hans Dieter Pearcey <hdp@cpan.org>
  • Chris Prather <chris@prather.org>
  • Matt S Trout <mstrout@cpan.org>

This software is copyright (c) 2006 by Infinity Interactive, Inc. 🩷

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. yes bestie, free as in freedom, go wild.


πŸ’– cute sign-off time: this lil page came from perl v5.42.0, dated 2025-07-25, in the User Contributed Perl Documentation. that's a wrap, bestie β€” go flip some switches πŸ”₯πŸ‘‘
πŸ“¦ where this page comes from