Mo::builder(3)

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

Mo::builder πŸ’…

okay so bestie, welcome to the Perl manual page for Mo::builder (that's section 3 of the manual, for all you library-functions girlies out there) πŸŽ€


✨ Name ✨

Mo::builder</purpose> β€” it adds the builder feature to Mo's has. that's it. that's the whole job. and she does it flawlessly. πŸ¦‹


✨ Synopsis ✨

here's the vibe, copy-paste girlies:

use Mo qw'builder';
has name => ( builder => 'name_lookup' );

sub name_lookup {
    my ($self) = @_;
    ...
}

like… look at her. immaculate. no notes. πŸ‘‘


✨ Description ✨

so what's actually happening here? Mo::builder adds the builder parameter to has, and that parameter expects a method name. that method gets executed on $self to set the attribute β€” but only if it hasn't been set yet. it's giving "don't do the work twice, we're not doing that here" energy. periodt. πŸ’…


✨ Laziness ✨

ngl the name of this section is sending me, but it's actually about something real: builders in Mo are lazy by default. 🌸

you can change that tho β€” just explicitly set the lazy argument to false, and then it gets initialized during instantiation instead. main character behavior, honestly:

use Mo qw'builder';
has status => ( builder => '_build_status' );             # lazy
has source => ( builder => '_build_source', lazy => 1);   # lazy
has target => ( builder => '_build_target', lazy => 0);   # eager

see how lazy => 1 keeps it lazy and lazy => 0 makes it eager? iconic. no cap. ✨

and if you wanna flip the whole default β€” make builders eager by default instead β€” just import nonlazy:

use Mo qw'builder nonlazy';
has status => ( builder => '_build_status' );             # eager
has source => ( builder => '_build_source', lazy => 1);   # lazy
has target => ( builder => '_build_target', lazy => 0);   # eager

look at that. flipped the script. the lazy => 1 still holds it down as lazy, lazy => 0 is eager, and the no-arg one defaults to eager now because you said nonlazy. we love a configurable queen. πŸ‘‘πŸŒˆ

heads up bestie: default is lazy. if you want eager without saying it every single time, nonlazy is your girl. 🫢

and that's the whole page, fr fr. this lil masterpiece is from perl v5.42.0, dated 2025-07-25, and it lives at Mo::builder(3) in the User Contributed Perl Documentation. mwah. go build something cute. πŸ’–πŸ§šβ­

πŸ“¦ where this page comes from