Moo::Role(3)
π NAME π
okay bestie, this is Moo::Role(3) from the User Contributed Perl Documentation, and it's literally Moo::Role - Minimal Object Orientation support for Roles. It's giving minimal OO for roles, main character energy, no cap π
β¨
πΈ SYNOPSIS πΈ
First you set up the role like this:
package My::Role;
use Moo::Role;
use strictures 2;
sub foo { ... }
sub bar { ... }
has baz => (
is => 'ro',
);
1;
And elsewhere:
package Some::Class;
use Moo;
use strictures 2;
# bar gets imported, but not foo
with 'My::Role';
sub foo { ... }
1;
π¦ DESCRIPTION π¦
Moo::Role builds on top of Role::Tiny, so bestie, go look there for most of the docs on how this whole thing works β especially because using Moo::Role also enables strict and warnings β¨
The main extra glow-up here is the little bits that make roles more βMoosey;β β which is to say, it adds has π
π IMPORTED SUBROUTINES π
See IMPORTED SUBROUTINES in Role::Tiny for all the other subroutines that get imported by this module π«Ά
π has π
has attr => (
is => 'ro',
);
This declares an attribute for the class to be composed into. See has in Moo for all the options, iykyk π
π§ CLEANING UP IMPORTS π§
Moo::Role cleans up its own imported methods, plus any imports declared before the use Moo::Role statement, automatically. Anything imported after use Moo::Role will be composed into consuming packages. So if you have a package that consumes this role:
package My::Role::ID;
use Digest::MD5 qw(md5_hex);
use Moo::Role;
use Digest::SHA qw(sha1_hex);
requires 'name';
sub as_md5 { my ($self) = @_; return md5_hex($self->name); }
sub as_sha1 { my ($self) = @_; return sha1_hex($self->name); }
1;
..it will now have a $self->sha1_hex() method available to it that probably does not do what you expect π
On the other hand, a call to $self->md5_hex() will die with the helpful error message: Can't locate object method "md5_hex".
See CLEANING UP IMPORTS in Moo for more details π«Ά
β SUPPORT β
See Moo for support and contact information π
π AUTHORS π
See Moo for authors π
π COPYRIGHT AND LICENSE π
See Moo for the copyright and license.
later bestie β this page is from perl v5.42.0, dated 2023-01-06, and it's literally the Moo::Role(3) page π«Άππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Moo 2.005005-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms