1CatalystX::Component::TUrsaeirtsC(o3n)tributed Perl DocuCmaetnatlaytsitoXn::Component::Traits(3)
2
3
4
6 CatalystX::Component::Traits - Automatic Trait Loading and Resolution
7 for Catalyst Components
8
10 Version 0.16
11
13 package Catalyst::Model::SomeModel;
14 with 'CatalystX::Component::Traits';
15
16 package MyApp::Model::MyModel;
17 use parent 'Catalyst::Model::SomeModel';
18
19 package MyApp;
20
21 __PACKAGE__->config('Model::MyModel' => {
22 traits => ['SearchedForTrait', '+Fully::Qualified::Trait']
23 });
24
26 Adds a "COMPONENT" in Catalyst::Component method to your Catalyst
27 component base class that reads the optional "traits" parameter from
28 app and component config and instantiates the component subclass with
29 those traits using "new_with_traits" in MooseX::Traits from
30 MooseX::Traits::Pluggable.
31
33 Trait names qualified with a "+" are taken to be full package names.
34
35 Unqualified names are searched for, using the algorithm described
36 below.
37
38 EXAMPLE
39 Suppose your inheritance hierarchy is:
40
41 MyApp::Model::MyModel
42 Catalyst::Model::CatModel
43 Catalyst::Model
44 Catalyst::Component
45 Moose::Object
46
47 The configuration is:
48
49 traits => ['Foo']
50
51 The package search order for "Foo" will be:
52
53 MyApp::TraitFor::Model::CatModel::Foo
54 Catalyst::TraitFor::Model::CatModel::Foo
55
56 A MORE PATHOLOGICAL EXAMPLE
57 For:
58
59 My::App::Controller::AController
60 CatalystX::Something::ControllerBase::SomeController
61 Catalyst::Controller
62 Catalyst::Model
63 Catalyst::Component
64 Moose::Object
65
66 With:
67
68 traits => ['Foo']
69
70 Search order for "Foo" will be:
71
72 My::App::TraitFor::Controller::SomeController::Foo
73 CatalystX::Something::TraitFor::Controller::SomeController::Foo
74
75 The "Base" after (M|V|C) is automatically removed.
76
78 Traits from component class config and app config are automatically
79 merged if you set the "_trait_merge" attribute default, e.g.:
80
81 has '+_trait_merge' => (default => 1);
82
83 You can remove component class config traits by prefixing their names
84 with a "-" in the app config traits.
85
86 For example:
87
88 package Catalyst::Model::Foo;
89 has '+_trait_merge' => (default => 1);
90 __PACKAGE__->config->{traits} = [qw/Foo Bar/];
91
92 package MyApp;
93 __PACKAGE__->config->{'Model::Foo'}{traits} = [qw/-Foo Baz/];
94
95 Will load the traits:
96
97 Bar Baz
98
100 Rafael Kitover, "<rkitover@cpan.org>"
101
103 Tomas Doran, "<bobtfish@bobtfish.net>"
104
106 Please report any bugs or feature requests to
107 "bug-catalystx-component-traits at rt.cpan.org", or through the web
108 interface at
109 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-Component-Traits
110 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-Component-
111 Traits>. I will be notified, and then you'll automatically be notified
112 of progress on your bug as I make changes.
113
115 More information at:
116
117 · RT: CPAN's request tracker
118
119 http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-Component-Traits
120 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-Component-
121 Traits>
122
123 · AnnoCPAN: Annotated CPAN documentation
124
125 http://annocpan.org/dist/CatalystX-Component-Traits
126 <http://annocpan.org/dist/CatalystX-Component-Traits>
127
128 · CPAN Ratings
129
130 http://cpanratings.perl.org/d/CatalystX-Component-Traits
131 <http://cpanratings.perl.org/d/CatalystX-Component-Traits>
132
133 · Search CPAN
134
135 http://search.cpan.org/dist/CatalystX-Component-Traits/
136 <http://search.cpan.org/dist/CatalystX-Component-Traits/>
137
139 Matt S. Trout and Tomas Doran helped me with the current design.
140
142 Copyright (c) 2009, Rafael Kitover
143
144 This program is free software; you can redistribute it and/or modify it
145 under the same terms as Perl itself.
146
147
148
149perl v5.12.2 2010-08-26 CatalystX::Component::Traits(3)