View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Tina Müller > Mo > Mo::option



Annotate this POD


View/Report Bugs
Module Version: 0.40   Source  

Name ^

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

Synopsis ^

    package Foo;

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

    my $f = Foo->new;

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

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

Description ^

This feature lets an accessor act as an option, that is intended to have a value of 1 or 0. Simply calling the accessor sets the value to 1, and returns the instance so you can chain to the next method.

To get the value of the attribute, call the "read_<name>" accessor. Here's a trick to do that when you are not assigning the value to anything:

syntax highlighting: