MooX::...::Util(3pm)

πŸ“¦
version 0.005 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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_namespace method β€” but only if the class does the MooX::Traits role β€” 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>.


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