README
1NAME
2 MooseX::Traits::Pluggable - trait loading and resolution for Moose
3
4DESCRIPTION
5 See MooseX::Traits for usage information.
6
7 Use "new_with_traits" to construct an object with a list of traits and
8 "apply_traits" to apply traits to an instance.
9
10 Adds support for class precedence search for traits and some extra
11 attributes, described below.
12
13TRAIT SEARCH
14 If the value of "_trait_namespace" in MooseX::Traits starts with a "+"
15 the namespace will be considered relative to the "class_precedence_list"
16 (ie. @ISA) of the original class.
17
18 Example:
19
20 package Class1
21 use Moose;
22
23 package Class1::Trait::Foo;
24 use Moose::Role;
25 has 'bar' => (
26 is => 'ro',
27 isa => 'Str',
28 required => 1,
29 );
30
31 package Class2;
32 use parent 'Class1';
33 with 'MooseX::Traits';
34 has '+_trait_namespace' => (default => '+Trait');
35 has '+_traits_behave_like_roles' => (default => 1);
36
37 package Class2::Trait::Bar;
38 use Moose::Role;
39 has 'baz' => (
40 is => 'ro',
41 isa => 'Str',
42 required => 1,
43 );
44
45 package main;
46 my $instance = Class2->new_with_traits(
47 traits => ['Foo', 'Bar'],
48 bar => 'baz',
49 baz => 'quux',
50 );
51
52 $instance->does('Class1::Trait::Foo'); # true
53 $instance->does('Class2::Trait::Bar'); # true
54
55NAMESPACE ARRAYS
56 You can search multiple namespaces for traits, for example:
57
58 has '+_trait_namespace' => (
59 default => sub { [qw/+Trait +Role ExtraNS::Trait/] }
60 );
61
62 Will search in the "class_precedence_list" for "::Trait::TheTrait" and
63 "::Role::TheTrait" and then for "ExtraNS::Trait::TheTrait".
64
65CORRECT ROLE BEHAVIOR
66 By default, a method from a role will override a class method, this
67 however is not the behavior one expects when applying a Moose role using
68 the normal methods.
69
70 If you want the behavior to be consistent with Moose roles, then use
71 this configuration attribute in your class:
72
73 has '+_traits_behave_like_roles' => (default => 1);
74
75 This may or may not become the default in the future, for now you have
76 to ask for it for backward compatibility reasons.
77
78EXTRA ATTRIBUTES
79 _original_class_name
80 When traits are applied to your class or instance, you get an anonymous
81 class back whose name will be not the same as your original class. So
82 "ref $self" will not be "Class", but "$self->_original_class_name" will
83 be.
84
85 _traits
86 List of the (unresolved) traits applied to the instance.
87
88 _resolved_traits
89 List of traits applied to the instance resolved to full package names.
90
91SEE ALSO
92 MooseX::Traits, MooseX::Object::Pluggable, CatalystX::Component::Traits
93
94BUGS
95 Please report any bugs or feature requests to
96 "bug-moosex-traits-pluggable at rt.cpan.org", or through the web
97 interface at
98 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Traits-Pluggable>
99 . I will be notified, and then you'll automatically be notified of
100 progress on your bug as I make changes.
101
102AUTHOR
103 Rafael Kitover "<rkitover@cpan.org>"
104
105CONTRIBUTORS
106 Tomas Doran, "<bobtfish@bobtfish.net>" Fitz Elliott,
107 "<fitz.elliott@gmail.com>" Andreas Marienborg,
108 "<andreas.marienborg@gmail.com>" Alexander Hartmaier,
109 "<abraxxa@cpan.org>"
110
111COPYRIGHT & LICENSE
112 Copyright (c) 2014 by the aforementioned "AUTHOR" and "CONTRIBUTORS".
113
114 This library is free software; you can redistribute it and/or modify it
115 under the same terms as Perl itself.
116
117