logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MooX::Traits::Util - non-role alternative to MooX::Traits

Author

       Toby Inkster <tobyink@cpan.org>.

Bugs

       Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=MooX-Traits>.

Description

       This module provides the functionality of MooX::Traits, but it's an exporter rather than a role.

       It's inspired by, but not compatible with MooseX::Traits::Util. The latter module is undocumented, and
       it's not entirely clear whether it's intended to be consumed by end-users, or is an entirely internal
       API.

       This module exports nothing by default.

   Functions
       "new_class_with_traits( $class, @traits )"
           Return a new class name with the traits applied.

           This  function  is  not  quite  compatible  with  the  "new_class_with_traits"  function  provided by
           MooseX::Traits::Util, in that the latter will return a metaclass object.

           This function can be exported.

       "new_class_with_traits_one_by_one( $class, @traits )"
           Rather than applying the the traits simultaneously, the traits are applied  one  at  a  time.  It  is
           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;

           Applying  traits one by one has implications for method modifiers, and for method conflict detection.
           Usewithcaution.

           There is no equivalent functionality in MooseX::Traits::Util.

           This function can be exported.

       "resolve_traits( $class, @traits )"
           This function returns a list of traits, but 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 handles parameter
           hashrefs for parameterizable roles. (That is, parameters are 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.)

           This  function  is  not  quite  compatible   with   the   "resolve_traits"   function   provided   by
           MooseX::Traits::Util,  in  that  the  latter will not handle parameter hashrefs, trusting Moose to do
           that.

           This function cannot be exported.

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.

perl v5.40.1                                       2025-02-18                            MooX::Traits::Util(3pm)

Name

       MooX::Traits::Util - non-role alternative to MooX::Traits

See Also

       MooX::Traits.

Synopsis

       Given some roles:

          package Role;
          use Moo::Role;
          has foo => ( is => 'ro', required => 1 );

       And a class:

          package Class;
          use Moo;

       Apply the roles to the class:

          use MooX::Traits::Util -all;

          my $class = new_class_with_traits('Class', 'Role');

       Then use your customized class:

          my $object = $class->new( foo => 42 );
          $object->isa('Class'); # true
          $object->does('Role'); # true
          $object->foo; # 42

See Also