MooseX...uggable(3pm)
π MooseX::Traits::Pluggable π
okay bestie, welcome to MooseX...uggable(3pm) β the User Contributed Perl Documentation page that's about to change your whole trait-loading life. no cap π¦
This is MooseX::Traits::Pluggable β it does trait loading and resolution for Moose. That's the whole vibe. Periodt. π
β¨ DESCRIPTION β¨
So like, for actual usage info, go read MooseX::Traits. That's the main character here, this module is the iconique plot twist.
You use new_with_traits to construct an object with a list of traits, and apply_traits to apply traits to an instance. That's it, that's the move. π
On top of that, this module adds support for class precedence search for traits and some extra attributes, which are described below. Keep scrolling bestie, the tea is further down. π
π TRAIT SEARCH π
Here's the moment. If the value of _trait_namespace in MooseX::Traits starts with a "+", then the namespace is considered relative to the class_precedence_list (ie. @ISA) of the original class. Yes, that @ISA. The ancestor list. The family tree. π³
Example:
package Class1
use Moose;
package Class1::Trait::Foo;
use Moose::Role;
has 'bar' => (
is => 'ro',
isa => 'Str',
required => 1,
);
package Class2;
use parent 'Class1';
with 'MooseX::Traits';
has '+_trait_namespace' => (default => '+Trait');
has '+_traits_behave_like_roles' => (default => 1);
package Class2::Trait::Bar;
use Moose::Role;
has 'baz' => (
is => 'ro',
isa => 'Str',
required => 1,
);
package main;
my $instance = Class2->new_with_traits(
traits => ['Foo', 'Bar'],
bar => 'baz',
baz => 'quux',
);
$instance->does('Class1::Trait::Foo'); # true
$instance->does('Class2::Trait::Bar'); # true
like, the trait Foo got found all the way up in Class1's namespace and Bar came from Class2's. it's giving inheritance but make it fashion. π
π NAMESPACE ARRAYS π
You can search multiple namespaces for traits, bestie. Multiple. Not just one. For example:
has '+_trait_namespace' => (
default => sub { [qw/+Trait +Role ExtraNS::Trait/] }
);
Will search in the class_precedence_list for ::Trait::TheTrait and ::Role::TheTrait and then for ExtraNS::Trait::TheTrait. In that order, okay? The order matters. It's a whole queue. π«Ά
π CORRECT ROLE BEHAVIOR π
okay this part is important, listen up.
By default, a method from a role will override a class method. However β and this is the gag β this is not the behavior one expects when applying a Moose role using the normal methods. So like, surprise! not in a cute way. π
If you want the behavior to be consistent with Moose roles, then use this configuration attribute in your class:
has '+_traits_behave_like_roles' => (default => 1);
This may or may not become the default in the future. For now you have to ask for it, for backward compatibility reasons. So don't be out here assuming, bestie β you gotta opt in. π§
π EXTRA ATTRIBUTES π
_original_class_name
When traits are applied to your class or instance, you get an anonymous class back whose name will be not the same as your original class. Rude, I know. So ref $self will not be Class, but $self->_original_class_name will be. It's the glow-up disguise situation β the identity is still in there. β¨
_traits
List of the (unresolved) traits applied to the instance. Just the raw list, no resolution, no nothing. Keepin' it real. π
_resolved_traits
List of traits applied to the instance resolved to full package names. This is the one that actually knows where everybody lives. π
π SEE ALSO π
MooseX::TraitsMooseX::Object::PluggableCatalystX::Component::Traits
π BUGS π
Please report any bugs or feature requests to bug-moosex-traits-pluggable at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Traits-Pluggable.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. So like, you're not screaming into the void, bestie. You'll get updates. That's the deal. π
π AUTHOR π
Rafael Kitover <rkitover@cpan.org>
πΈ CONTRIBUTORS πΈ
Tomas Doran, <bobtfish@bobtfish.net> Fitz Elliott, <fitz.elliott@gmail.com> Andreas Marienborg, <andreas.marienborg@gmail.com> Alexander Hartmaier, <abraxxa@cpan.org>
π COPYRIGHT & LICENSE π
Copyright (c) 2014 by the aforementioned AUTHOR and CONTRIBUTORS.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page, you ate it, you read the whole thing, I'm so proud of you π«Ά
this was perl v5.34.0, dated 2022-06-15, and you just finished the MooseX...uggable(3pm) page β the User Contributed Perl Documentation, iconic behavior, no notes. π β¨ π π¦ πΈ π
β
π¦ where this page comes from
- debian bookworm: libmoosex-traits-pluggable-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-traits-pluggable-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-traits-pluggable-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-traits-pluggable-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-traits-pluggable-perl 0.12-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