Mo::build(3)
π Mo::build π
okay bestie, so this is Mo::build from the User Contributed Perl Documentation section of the manual (manual page Mo::build(3), iykyk). It's the lil add-on that gives Mo its β¨buildβ¨ era.
πΈ NAME πΈ
Mo::build β adds the build feature to Mo π
β¨ SYNOPSIS β¨
use Mo qw'build';
has name => ( is => 'rw' );
sub BUILD {
my $self = shift;
...
}
π¦ DESCRIPTION π¦
So the way this works is: the moment you import it, it adds the BUILD feature to Mo. That's the whole vibe. π
If there's a sub called BUILD hangin' out on the package, it gets run on $self during instantiation. Like, right in the middle of the whole "new object just dropped" moment. π
And here's the tea: any non-lazy default and builder attributes, plus anything you passed into new, are already set by the time BUILD gets called. So you can just reach in and read them, no stress. π«Ά
package ABCD;
use Mo qw'build builder default';
use feature 'say';
has a => (default => 1234, lazy => 0);
has b => (builder => '_b', lazy => 0);
has c => (is => 'rw');
has d => (is => 'rw');
sub _b { 'blue' }
sub BUILD {
my ($self) = @_;
say $self->{a};
say $self->{b};
say $self->{c};
say 'undef' unless defined $self->{d};
}
ABCD->new(c => 'days') # => 1234
# blue
# days
# undef
like... a shows up as 1234 because of the default, b is blue from the builder, c is days 'cause we passed it to new, and d is just out here being undef π not me crying over an undefined attribute. The lazy => 0 on a and b is literally why they're ready in time β non-lazy stays on business. β
π reminder bestie: only non-lazydefault/builderstuff is guaranteed to be set whenBUILDfires. Don't come for me if your lazy attributes are still napping. π
perl v5.42.0 Β· 2025-07-25 β mwah, that's the version and the date this lil page was born, shoutout to the perl folks, and slay, you made it to the end, go build something iconic π§π
π¦ where this page comes from
- fedora 43: perl-Mo 0.40-28.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms