.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "MooX::Traits::Util 3pm" .TH MooX::Traits::Util 3pm "2018-09-02" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooX::Traits::Util \- non\-role alternative to MooX::Traits .SH "SYNOPSIS" .IX Header "SYNOPSIS" Given some roles: .PP .Vb 3 \& package Role; \& use Moo::Role; \& has foo => ( is => \*(Aqro\*(Aq, required => 1 ); .Ve .PP And a class: .PP .Vb 2 \& package Class; \& use Moo; .Ve .PP Apply the roles to the class: .PP .Vb 1 \& use MooX::Traits::Util \-all; \& \& my $class = new_class_with_traits(\*(AqClass\*(Aq, \*(AqRole\*(Aq); .Ve .PP Then use your customized class: .PP .Vb 4 \& my $object = $class\->new( foo => 42 ); \& $object\->isa(\*(AqClass\*(Aq); # true \& $object\->does(\*(AqRole\*(Aq); # true \& $object\->foo; # 42 .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides the functionality of MooX::Traits, but it's an exporter rather than a role. .PP 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 \s-1API.\s0 .PP This module exports nothing by default. .SS "Functions" .IX Subsection "Functions" .ie n .IP """new_class_with_traits( $class, @traits )""" 4 .el .IP "\f(CWnew_class_with_traits( $class, @traits )\fR" 4 .IX Item "new_class_with_traits( $class, @traits )" Return a new class name with the traits applied. .Sp This function is not quite compatible with the \f(CW\*(C`new_class_with_traits\*(C'\fR function provided by MooseX::Traits::Util, in that the latter will return a metaclass object. .Sp This function can be exported. .ie n .IP """new_class_with_traits_one_by_one( $class, @traits )""" 4 .el .IP "\f(CWnew_class_with_traits_one_by_one( $class, @traits )\fR" 4 .IX Item "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: .Sp .Vb 2 \& 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; .Ve .Sp Applying traits one by one has implications for method modifiers, and for method conflict detection. \fBUse with caution.\fR .Sp There is no equivalent functionality in MooseX::Traits::Util. .Sp This function can be exported. .ie n .IP """resolve_traits( $class, @traits )""" 4 .el .IP "\f(CWresolve_traits( $class, @traits )\fR" 4 .IX Item "resolve_traits( $class, @traits )" This function returns a list of traits, but does not apply them to the class. It honours the class' \f(CW\*(C`_trait_namespace\*(C'\fR 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.) .Sp This function is not quite compatible with the \f(CW\*(C`resolve_traits\*(C'\fR function provided by MooseX::Traits::Util, in that the latter will not handle parameter hashrefs, trusting Moose to do that. .Sp This function \fIcannot\fR be exported. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" MooX::Traits. .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2014 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" \&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0