1Mo::option(3)         User Contributed Perl Documentation        Mo::option(3)
2
3
4

Name

6       Mo::option - Allow an attribute to be a chainable, boolean option.
7

Synopsis

9           package Foo;
10
11           use Mo qw'option';
12           has this => ( option => 1 );
13           has that => ( option => 1 );
14
15           my $f = Foo->new;
16           $f->this->that(0)->do_something;
17
18           my $this = $f->read_this;   # 1
19           my $that = $f->read_that;   # 0
20
21           $f->do_something if $f->read_this;
22

Description

24       This feature lets an accessor act as an option, that is intended to
25       have a value of 1 or 0. Simply calling the accessor sets the value to
26       1, and returns the instance so you can chain to the next method.
27
28       To get the value of the attribute, call the "read_<name>" accessor.
29       Here's a trick to do that when you are not assigning the value to
30       anything:
31
32
33
34perl v5.32.1                      2021-01-27                     Mo::option(3)
Impressum