1MooseX::Traits::PluggabUlsee(r3)Contributed Perl DocumenMtoaotsieoXn::Traits::Pluggable(3)
2
3
4

NAME

6       MooseX::Traits::Pluggable - trait loading and resolution for Moose
7

DESCRIPTION

9       See MooseX::Traits for usage information.
10
11       Use "new_with_traits" to construct an object with a list of traits and
12       "apply_traits" to apply traits to an instance.
13
14       Adds support for class precedence search for traits and some extra
15       attributes, described below.
16
18       If the value of "_trait_namespace" in MooseX::Traits starts with a "+"
19       the namespace will be considered relative to the
20       "class_precedence_list" (ie.  @ISA) of the original class.
21
22       Example:
23
24         package Class1
25         use Moose;
26
27         package Class1::Trait::Foo;
28         use Moose::Role;
29         has 'bar' => (
30             is       => 'ro',
31             isa      => 'Str',
32             required => 1,
33         );
34
35         package Class2;
36         use parent 'Class1';
37         with 'MooseX::Traits';
38         has '+_trait_namespace' => (default => '+Trait');
39         has '+_traits_behave_like_roles' => (default => 1);
40
41         package Class2::Trait::Bar;
42         use Moose::Role;
43         has 'baz' => (
44             is       => 'ro',
45             isa      => 'Str',
46             required => 1,
47         );
48
49         package main;
50         my $instance = Class2->new_with_traits(
51             traits => ['Foo', 'Bar'],
52             bar => 'baz',
53             baz => 'quux',
54         );
55
56         $instance->does('Class1::Trait::Foo'); # true
57         $instance->does('Class2::Trait::Bar'); # true
58

NAMESPACE ARRAYS

60       You can search multiple namespaces for traits, for example:
61
62         has '+_trait_namespace' => (
63             default => sub { [qw/+Trait +Role ExtraNS::Trait/] }
64         );
65
66       Will search in the "class_precedence_list" for "::Trait::TheTrait" and
67       "::Role::TheTrait" and then for "ExtraNS::Trait::TheTrait".
68

CORRECT ROLE BEHAVIOR

70       By default, a method from a role will override a class method, this
71       however is not the behavior one expects when applying a Moose role
72       using the normal methods.
73
74       If you want the behavior to be consistent with Moose roles, then use
75       this configuration attribute in your class:
76
77         has '+_traits_behave_like_roles' => (default => 1);
78
79       This may or may not become the default in the future, for now you have
80       to ask for it for backward compatibility reasons.
81

EXTRA ATTRIBUTES

83   _original_class_name
84       When traits are applied to your class or instance, you get an anonymous
85       class back whose name will be not the same as your original class. So
86       "ref $self" will not be "Class", but "$self->_original_class_name" will
87       be.
88
89   _traits
90       List of the (unresolved) traits applied to the instance.
91
92   _resolved_traits
93       List of traits applied to the instance resolved to full package names.
94

SEE ALSO

96       MooseX::Traits, MooseX::Object::Pluggable, CatalystX::Component::Traits
97

BUGS

99       Please report any bugs or feature requests to
100       "bug-moosex-traits-pluggable at rt.cpan.org", or through the web
101       interface at
102       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Traits-Pluggable>.
103       I will be notified, and then you'll automatically be notified of
104       progress on your bug as I make changes.
105

AUTHOR

107       Rafael Kitover "<rkitover@cpan.org>"
108

CONTRIBUTORS

110       Tomas Doran, "<bobtfish@bobtfish.net>" Fitz Elliott,
111       "<fitz.elliott@gmail.com>" Andreas Marienborg,
112       "<andreas.marienborg@gmail.com>" Alexander Hartmaier,
113       "<abraxxa@cpan.org>"
114
116       Copyright (c) 2014 by the aforementioned "AUTHOR" and "CONTRIBUTORS".
117
118       This library is free software; you can redistribute it and/or modify it
119       under the same terms as Perl itself.
120
121
122
123perl v5.32.0                      2020-07-28      MooseX::Traits::Pluggable(3)
Impressum