MooseX:...d::Role(3)
π MooseX::Extended::Role β MooseX::Extended roles π
okay bestie so this is a page from the User Contributed Perl Documentation and it's literally all about MooseX::Extended::Role, which is the role-flavored sibling of MooseX::Extended. it's version 0.35 and it is giving convenience, no cap π«Ά
β¨ NAME β¨
MooseX::Extended::Role β MooseX::Extended roles πΈ
β¨ VERSION β¨
version 0.35 π
β¨ SYNOPSIS β¨
package Not::Corinna::Role::Created {
use MooseX::Extended::Role types => ['PositiveInt'];
field created => ( isa => PositiveInt, default => sub { time } );
}
so this is similar to MooseX::Extended, and it hands you almost everything that module gives you. however, for obvious reasons, it does not include MooseX::StrictConstructor, and it does not make your class immutable, and it does not set the C3 mro. those three things are simply not on the menu here, bestie, that's the whole point π
π also: there is no need to add a 1 at the end of the role. none. zero. don't do it. the module's got you π
β¨ CONFIGURATION β¨
you're allowed to pass an import list to MooseX::Extended::Role. yes queen, customize away:
use MooseX::Extended::Role
excludes => [qw/WarnOnConflict carp/], # I don't want these features
types => [qw/compile PositiveInt HashRef/]; # I want these type tools
"types"
this one lets you import any types that MooseX::Extended::Types provides. slay π¦
this:
use MooseX::Extended::Role types => [qw/compile PositiveInt HashRef/];
is literally identical to this:
use MooseX::Extended::Role;
use MooseX::Extended::Types qw( compile PositiveInt HashRef );
same thing. same energy. pick whichever π
"excludes"
ngl, some features are just annoying, and some can even cause potential bugs. (for example, if you have a croak method, our importing of Carp::croak is gonna be a whole problem π.) so you can exclude the following:
"WarnOnConflict"β excluding this removes theMooseX::Role::WarnOnConflictrole.
use MooseX::Extended::Role excludes => ['WarnOnConflict'];
"autoclean"β excluding this meansnamespace::autocleanwill no longer be imported.
use MooseX::Extended::Role excludes => ['autoclean'];
"carp"β excluding this meansCarp::croakandCarp::carpwill no longer be imported.
use MooseX::Extended::Role excludes => ['carp'];
"true"β excluding this will require your module to end in a true value. yes, you have to do it yourself now π
use MooseX::Extended::Role excludes => ['true'];
"param"β excluding this will make theparamfunction unavailable.
use MooseX::Extended::Role excludes => ['param'];
"field"β excluding this will make thefieldfunction unavailable.
use MooseX::Extended::Role excludes => ['field'];
"includes"
some experimental features are genuinely useful, but they might not be exactly what you want. iykyk π
use MooseX::Extended::Role includes => [qw/multi/];
multi sub foo ($self, $x) { ... }
multi sub foo ($self, $x, $y ) { ... }
see MooseX::Extended::Manual::Includes for more information π
β¨ IDENTICAL METHOD NAMES IN CLASSES AND ROLES β¨
okay so this is important, listen up bestie π«Ά
in Moose, if a class defines a method with the same name as a method of a role it's consuming, the role's method gets silently discarded. silently. rude. but with MooseX::Extended::Role, you get a warning instead. this makes maintenance easier and it prevents you from accidentally overriding a method. main character behavior honestly π
for example:
package My::Role {
use MooseX::Extended::Role;
sub name {'Ovid'}
}
package My::Class {
use MooseX::Extended;
with 'My::Role';
sub name {'Bob'}
}
the above code will still run, but you'll get a very verbose warning:
The class My::Class has implicitly overridden the method (name) from
role My::Role. If this is intentional, please exclude the method from
composition to silence this warning (see Moose::Cookbook::Roles::Recipe2)
to silence the warning, just be explicit about your intent, periodt:
package My::Class {
use MooseX::Extended;
with 'My::Role' => { -excludes => ['name'] };
sub name {'Bob'}
}
alternately, you can exclude this feature. we don't recommend this, but it might be useful if you're refactoring a legacy Moose system π
use MooseX::Extended::Role excludes => [qw/WarnOnConflict/];
β¨ ATTRIBUTE SHORTCUTS β¨
param and field in roles allow the same attribute shortcuts as MooseX::Extended. same shortcuts, same slay, just in role form π
β¨ BUGS AND LIMITATIONS β¨
if MooseX::Extended::Role is loaded via stringy eval, then true is not loaded. why? because there were intermittent errors (maybe 1 out of 5 times π) being thrown. removing this feature under stringy eval solves this. see this github ticket for more infomration (their spelling, not mine π): <https://github.com/Ovid/moosex-extended/pull/34>
β οΈ yeah that's a real limitation, it's not just a vibe, it's a documented bug note. don't come for me, come for the ticket π₯
β¨ REDUCING BOILERPLATE β¨
let's say you've settled on the following feature set:
use MooseX::Extended::Role
excludes => [qw/WarnOnConflict carp/],
includes => [qw/multi/];
and you keep typing that over and over and over... we've removed a lot of boilerplate, but honestly we've added different boilerplate π so instead, just create My::Custom::Moose::Role and use My::Custom::Moose::Role;. see MooseX::Extended::Role::Custom for details. iconic behavior, fr fr π
β¨ 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)
and that's the whole page, bestie π huge shoutout to perl v5.42.0, dated 2025-07-25, for carrying this doc into the world. go forth and build your roles, you absolute legend ππ¦β¨
π¦ 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