MooX::Traits(3pm)
π MooX::Traits π
okay bestie, so this is MooX::Traits β it's a Perl module from the User Contributed Perl Documentation crew, and it's literally just here to automatically apply roles at object creation time. that's the whole vibe. let's get into it π¦
β¨ NAME β¨
MooX::Traits β automatically apply roles at object creation time. no cap, that's it. π
β¨ SYNOPSIS β¨
okay so picture this: you got some roles.
package Role;
use Moo::Role;
has foo => ( is => 'ro', required => 1 );
and then a class:
package Class;
use Moo;
with 'MooX::Traits';
now you apply the roles to the class:
my $class = Class->with_traits('Role');
and then you get to use your customized class:
my $object = $class->new( foo => 42 );
$object->isa('Class'); # true
$object->does('Role'); # true
$object->foo; # 42
likeβ¦ look at her go π
β¨ DESCRIPTION β¨
was any of that SYNOPSIS giving unexpected?? π because basically, this module is the exact same thing as MooseX::Traits and MouseX::Traits, only for Moo. Quelle surprise, right? (yes bestie that's the original's little French moment, we keep it, it's iconic)
πΈ Methods πΈ
$class->with_traits( @traits )β returns a new class name with the traits applied. this is the main character fr fr.$class->new_with_traits(%args, traits => \@traits)βnew_with_traitscan also take a hashref, e.g.:
my $instance = $class->new_with_traits({ traits => \@traits, foo => 'bar' });
ngl, this method exists purely for compatibility with the MooseX and MouseX equivalents of this module. but generally speaking? you should prefer to use with_traits. do it for me. π«Ά
$class->_trait_namespaceβ this returnsundef, but you can override it in your class to automatically prepend a namespace to supplied traits.
heads up bestie: this differs slightly from the MooseX and MouseX versions of this module, which have _trait_namespace as an attribute instead of a method. different energy, same name, don't get it twisted. π
π Compatibility π
even though it's called MooX::Traits, this module actually uses Role::Tiny, so it doesn't really require Moo. plot twist. if you use it in a non-Moo class, you should be able to safely consume any Role::Tiny-based traits. β¨
if you use it in a Moo class, you should also be able to consume Moo::Role-based traits and Moose::Role-based traits. slay.
Package::Variant and MooseX::Role::Parameterized roles should be usable too β just provide a hashref of arguments:
$class->with_traits( $param_role => \%args )->new( ... )
β¨ BUGS β¨
found a bug? π please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=MooX-Traits>. do it, you'll feel better.
β¨ SEE ALSO β¨
MooX::Traits::Util.Moo::Role,Role::Tiny.MooseX::Traits,MouseX::Traits.
β¨ AUTHOR β¨
Toby Inkster <tobyink@cpan.org>. π
β¨ COPYRIGHT AND LICENCE β¨
This software is copyright (c) 2014 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
β¨ DISCLAIMER OF WARRANTIES β¨
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
like, they said it in all caps so you know they mean it. no warranty bestie, we're all just out here vibing. π
okay that's the whole page!! this was perl v5.32.0 energy, dated 2021-01-24, and it's the MooX::Traits(3pm) page from User Contributed Perl Documentation. mwah π bye bestie, go apply some roles π¦β¨
π¦ where this page comes from
- debian bookworm: libmoox-traits-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoox-traits-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libmoox-traits-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoox-traits-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms