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