.\" 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 3pm" .TH MooX::Traits 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 \- automatically apply roles at object creation time .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 3 \& package Class; \& use Moo; \& with \*(AqMooX::Traits\*(Aq; .Ve .PP Apply the roles to the class: .PP .Vb 1 \& my $class = Class\->with_traits(\*(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" Was any of the \s-1SYNOPSIS\s0 unexpected? Basically, this module is the same thing as MooseX::Traits and MouseX::Traits, only for Moo. \&\fIQuelle surprise\fR, right? .SS "Methods" .IX Subsection "Methods" .ie n .IP """$class\->with_traits( @traits )""" 4 .el .IP "\f(CW$class\->with_traits( @traits )\fR" 4 .IX Item "$class->with_traits( @traits )" Return a new class name with the traits applied. .ie n .IP """$class\->new_with_traits(%args, traits => \e@traits)""" 4 .el .IP "\f(CW$class\->new_with_traits(%args, traits => \e@traits)\fR" 4 .IX Item "$class->new_with_traits(%args, traits => @traits)" \&\f(CW\*(C`new_with_traits\*(C'\fR can also take a hashref, e.g.: .Sp .Vb 1 \& my $instance = $class\->new_with_traits({ traits => \e@traits, foo => \*(Aqbar\*(Aq }); .Ve .Sp This method exists for compatibility with the MooseX and MouseX equivalents of this module, but generally speaking you should prefer to use \f(CW\*(C`with_traits\*(C'\fR. .ie n .IP """$class\->_trait_namespace""" 4 .el .IP "\f(CW$class\->_trait_namespace\fR" 4 .IX Item "$class->_trait_namespace" This returns undef, but you can override it in your class to automatically prepend a namespace to supplied traits. .Sp This differs slightly from the MooseX and MouseX versions of this module which have \f(CW\*(C`_trait_namespace\*(C'\fR as an attribute instead of a method. .SS "Compatibility" .IX Subsection "Compatibility" Although called MooX::Traits, this module actually uses Role::Tiny, so doesn't really require Moo. If you use it in a non-Moo class, you should be able to safely consume any Role::Tiny\-based traits. .PP If you use it in a Moo class, you should also be able to consume Moo::Role\-based traits and Moose::Role\-based traits. .PP Package::Variant and MooseX::Role::Parameterized roles should be usable; just provide a hashref of arguments: .PP .Vb 1 \& $class\->with_traits( $param_role => \e%args )\->new( ... ) .Ve .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" MooX::Traits::Util. .PP Moo::Role, Role::Tiny. .PP MooseX::Traits, MouseX::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