MooseX:...hortcuts(3)
โจ NAME โจ
MooseX::Extended::Manual::Shortcuts โ aka the manual page for MooseX::Extended that hands you a whole bag of shortcuts so writing your Moose code is lowkey effortless ๐
It's MooseX:...hortcuts(3), from the User Contributed Perl Documentation, and bestie, it's giving "quality of life update" fr fr.
๐ธ VERSION ๐ธ
version 0.35
๐ ATTRIBUTE SHORTCUTS ๐
Okay so when you're using field or param, the module is like "here, let me carry that for you" and gives you a bunch of attribute shortcuts:
param name => (
isa => NonEmptyStr,
writer => 1, # set_name
reader => 1, # get_name
predicate => 1, # has_name
clearer => 1, # clear_name
builder => 1, # _build_name
);
sub _build_name ($self) {
...
}
And these hit the same when you pass an array reference to the function, no cap:
package Point {
use MooseX::Extended types => ['Int'];
param [ 'x', 'y' ] => (
isa => Int,
clearer => 1, # clear_x and clear_y available
default => 0,
);
}
So like โ these are shortcuts, and they exist to make attributes easier to write and way more consistent. That's the vibe. But you can absolutely still use the full names if you want to be extra:
field authz_delegate => (
builder => '_build_my_darned_authz_delegate',
);
These are very similar to [MooseX::AttributeShortcuts](https://metacpan.org/pod/MooseX::AttributeShortcuts), but heads up, the naming is a little different. Example time: clearer => 1 for a _name attribute creates a clear__name method. But for MooseX::AttributeShortcuts, it would have been named _clear_name. Different name, same energy, don't get it twisted ๐ซถ
You still have the has function available for defining attributes, but it is unchanged. These shortcuts will not work with it. It's just not that girl.
โ๏ธ writer โ๏ธ
If an attribute has writer set to 1 (the number one, not a truthy-ish whatever), a method named set_$attribute_name is created.
This:
param title => (
isa => Undef | NonEmptyStr,
default => undef,
writer => 1,
);
Is the same as this:
has title => (
is => 'rw', # we change this from 'ro'
isa => Undef | NonEmptyStr,
default => undef,
writer => 'set_title',
);
๐ reader ๐
By default, the reader (accessor) for the attribute is the same as the name. You can always change this:
has payload => ( is => 'ro', reader => 'the_payload' );
However, if you want to change the reader nameโฆ
If an attribute has reader set to 1 (the number one), a method named get_$attribute_name is created.
This:
param title => (
isa => Undef | NonEmptyStr,
default => undef,
reader => 1,
);
Is the same as this:
has title => (
is => 'rw', # we change this from 'ro'
isa => Undef | NonEmptyStr,
default => undef,
reader => 'get_title',
);
๐ predicate ๐
If an attribute has predicate set to 1 (the number one), a method named has_$attribute_name is created.
This:
param title => (
isa => Undef | NonEmptyStr,
default => undef,
predicate => 1,
);
Is the same as this:
has title => (
is => 'ro',
isa => Undef | NonEmptyStr,
default => undef,
predicate => 'has_title',
);
๐งผ clearer ๐งผ
If an attribute has clearer set to 1 (the number one), a method named clear_$attribute_name is created.
This:
param title => (
isa => Undef | NonEmptyStr,
default => undef,
clearer => 1,
);
Is the same as this:
has title => (
is => 'ro',
isa => Undef | NonEmptyStr,
default => undef,
clearer => 'clear_title',
);
๐๏ธ builder ๐๏ธ
If an attribute has builder set to 1 (the number one), a method named _build_$attribute_name.
This:
param title => (
isa => NonEmptyStr,
builder => 1,
);
Is the same as this:
has title => (
is => 'ro',
isa => NonEmptyStr,
builder => '_build_title',
);
Obviously, a "private" attribute, such as _auth_token would get a build named _build__auth_token (note the two underscores between build and auth_token). Yeah. Two of them. That's just how it do ๐
๐ฎ STEALING FROM MOO ๐ฎ
๐ is => 'rwp' ๐
param name => ( is => 'rwp' );
The above is equivalent to:
has name => ( is => 'ro', writer => '_set_name' );
Of course, it works for field, too. Equal opportunity and all that โจ
๐งฌ builder Code References ๐งฌ
You may also pass a coderef to builder:
field created => (
isa => PositiveInt,
lazy => 0,
builder => sub {time},
);
This is different from default => sub {...} because it will install a _build_created method for you. This is useful if you with to allow a subclass to override this method. Slay, honestly. Inheritance queen behavior ๐
๐ฉบ DIAGNOSTICS ๐ฉบ
Attributes defined using param or field which are read-only with no init_arg and no default or builder, will result in a warning. If you wish to disable this warning you can.
no warnings 'MooseX::Extended::naked_fields';
Heads up bestie: this warning is only available on Perl >= 5.028. Older Perls simply won't be participating, sorry ๐ญ
๐ AUTHOR ๐
Curtis "Ovid" Poe <curtis.poe@gmail.com>
๐ COPYRIGHT AND LICENSE ๐
This software is Copyright (c) 2022 by Curtis "Ovid" Poe.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
That's the whole page, bestie, you ate it up ๐ This was MooseX:...hortcuts(3) from the User Contributed Perl Documentation, perl v5.42.0, dated 2025-07-25 โ go forth and write your attributes the easy way, periodt ๐ฆ๐ธ๐
๐ฆ where this page comes from
- fedora 43: perl-MooseX-Extended 0.35-6.fc43 ยท Artistic-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms