MooX::...::Util(3pm)
π NAME π
MooX::Traits::Util β bestie, it's the non-role alternative to MooX::Traits β¨
(and yeah, the manpage header says MooX::...::Util(3pm) β that's just the page title, we're talking about MooX::Traits::Util here π«Ά)
πΈ SYNOPSIS πΈ
okay so imagine you got some roles, right? like this:
package Role;
use Moo::Role;
has foo => ( is => 'ro', required => 1 );
and then a class:
package Class;
use Moo;
now you apply the roles to the class, boom:
use MooX::Traits::Util -all;
my $class = new_class_with_traits('Class', 'Role');
and then you just... use your customized class π
my $object = $class->new( foo => 42 );
$object->isa('Class'); # true
$object->does('Role'); # true
$object->foo; # 42
like. it just works. iconic. β¨
π¦ DESCRIPTION π¦
This module gives you all the functionality of MooX::Traits, but here's the plot twist: it's an exporter, not a role. not me switching up the whole format π
It's inspired by MooseX::Traits::Util, but not compatible with it, bestie. And the reason is lowkey funny: that other module is undocumented, and honestly nobody's sure whether it's meant to be consumed by end-users at all, or if it's just an entirely internal API. mystery behaviour fr fr π
Heads up: this module exports nothing by default. you gotta ask for it.
β¨ Functions β¨
new_class_with_traits( $class, @traits )β returns a new class name with the traits applied. slay.
So, this function is not quite compatible with the new_class_with_traits function that MooseX::Traits::Util provides β the difference being that the other one returns a metaclass object.
This function can be exported. π
new_class_with_traits_one_by_one( $class, @traits )β instead of applying the traits all at once simultaneously, the traits get applied one at a time. It's roughly equivalent to:
use List::Util qw(reduce);
use MooX::Traits::Util qw( new_class_with_traits );
my $class = ...;
my @traits = ...;
my $new = reduce { new_class_with_traits($a, $b) } $class, @traits;
β οΈ okay this part matters: applying traits one by one has implications for method modifiers, and for method conflict detection. Use with caution. like, genuinely. caution.
There is no equivalent functionality in MooseX::Traits::Util.
This function can be exported. π
resolve_traits( $class, @traits )β this one returns a list of traits, but it does not apply them to the class. It honours the class'_trait_namespacemethod β but only if the class does theMooX::Traitsrole β and it handles parameter hashrefs for parameterizable roles. (In other words: parameters get applied to the role, and the list of traits returned by the function includes the result of that application instead of including the original hashref. got it? got it. π )
This function is not quite compatible with the resolve_traits function provided by MooseX::Traits::Util, because that one will not handle parameter hashrefs β it trusts Moose to do that instead.
This function cannot be exported. sorry bestie π
π BUGS π
Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=MooX-Traits>.
(not me asking you nicely to file a ticket π₯Ί)
π SEE ALSO π
MooX::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.
and that's the whole vibe check, bestie π this page is from perl v5.32.0, dated 2021-01-24, and it's the MooX::...::Util(3pm) manual page. go forth and trait-ify responsibly π¦β¨
π¦ 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