Mo::option(3)

πŸ“¦
version 0.40 Β· 2 versions
, in fedora 43

✨ NAME ✨

Mo::option β€” bestie, this lets an attribute be a chainable, boolean option. πŸ’…


🌸 SYNOPSIS 🌸

package Foo;

use Mo qw'option';
has this => ( option => 1 );
has that => ( option => 1 );

my $f = Foo->new;
$f->this->that(0)->do_something;

my $this = $f->read_this;   # 1
my $that = $f->read_that;   # 0

$f->do_something if $f->read_this;

πŸŽ€ DESCRIPTION πŸŽ€

okay so this feature lets an accessor act like an option β€” and by "option" we mean it's intended to hold a value of 1 or 0. that's the vibe. πŸ¦‹

the way it works is lowkey iconic: just calling the accessor sets the value to 1, and then it hands you back the instance so you can keep chaining straight into the next method. main character energy fr fr. πŸ’–

to actually get the value of the attribute, you call the read_<name> accessor instead. and here's a trick to do that when you are not assigning the value to anything: 🫢


k bye bestie, this page is from the User Contributed Perl Documentation for Mo::option(3), and it's serving perl v5.42.0, dated 2025-07-25. slay. βœ¨πŸ‘‘

πŸ“¦ where this page comes from