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 package Catalyst::Model::SomeModel;
11 with 'CatalystX::Component::Traits';
12
13 package MyApp::Model::MyModel;
14 use parent 'Catalyst::Model::SomeModel';
15
16 package MyApp;
17
18 __PACKAGE__->config('Model::MyModel' => {
19 traits => ['SearchedForTrait', '+Fully::Qualified::Trait']
20 });
21
23 Adds a "COMPONENT" in Catalyst::Component method to your Catalyst
24 component base class that reads the optional "traits" parameter from
25 app and component config and instantiates the component subclass with
26 those traits using "new_with_traits" in MooseX::Traits from
27 MooseX::Traits::Pluggable.
28
30 Trait names qualified with a "+" are taken to be full package names.
31
32 Unqualified names are searched for, using the algorithm described
33 below.
34
35 EXAMPLE
36 Suppose your inheritance hierarchy is:
37
38 MyApp::Model::MyModel
39 Catalyst::Model::CatModel
40 Catalyst::Model
41 Catalyst::Component
42 Moose::Object
43
44 The configuration is:
45
46 traits => ['Foo']
47
48 The package search order for "Foo" will be:
49
50 MyApp::TraitFor::Model::CatModel::Foo
51 Catalyst::TraitFor::Model::CatModel::Foo
52
53 A MORE PATHOLOGICAL EXAMPLE
54 For:
55
56 My::App::Controller::AController
57 CatalystX::Something::ControllerBase::SomeController
58 Catalyst::Controller
59 Catalyst::Model
60 Catalyst::Component
61 Moose::Object
62
63 With:
64
65 traits => ['Foo']
66
67 Search order for "Foo" will be:
68
69 My::App::TraitFor::Controller::SomeController::Foo
70 CatalystX::Something::TraitFor::Controller::SomeController::Foo
71
72 The "Base" after (M|V|C) is automatically removed.
73
75 Traits from component class config and app config are automatically
76 merged if you set the "_trait_merge" attribute default, e.g.:
77
78 has '+_trait_merge' => (default => 1);
79
80 You can remove component class config traits by prefixing their names
81 with a "-" in the app config traits.
82
83 For example:
84
85 package Catalyst::Model::Foo;
86 has '+_trait_merge' => (default => 1);
87 __PACKAGE__->config->{traits} = [qw/Foo Bar/];
88
89 package MyApp;
90 __PACKAGE__->config->{'Model::Foo'}{traits} = [qw/-Foo Baz/];
91
92 Will load the traits:
93
94 Bar Baz
95
97 Rafael Kitover, "<rkitover@cpan.org>"
98
100 Tomas Doran, "<bobtfish@bobtfish.net>"
101
103 Please report any bugs or feature requests to
104 "bug-catalystx-component-traits at rt.cpan.org", or through the web
105 interface at
106 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-Component-Traits>.
107 I will be notified, and then you'll automatically be notified of
108 progress on your bug as I make changes.
109
111 Matt S. Trout and Tomas Doran helped me with the current design.
112
114 Copyright (c) 2014, Rafael Kitover
115
116 This program is free software; you can redistribute it and/or modify it
117 under the same terms as Perl itself.
118
119
120
121perl v5.34.0 2022-01-21 CatalystX::Component::Traits(3)