Cataly...Traits(3pm)
π NAME π
CatalystX::Component::Traits β automatic trait loading and resolution for Catalyst components, bestie. like it literally does the trait thing for you so you don't have to π
β¨ SYNOPSIS β¨
package Catalyst::Model::SomeModel;
with 'CatalystX::Component::Traits';
package MyApp::Model::MyModel;
use parent 'Catalyst::Model::SomeModel';
package MyApp;
__PACKAGE__->config('Model::MyModel' => {
traits => ['SearchedForTrait', '+Fully::Qualified::Trait']
});
okay that's the whole vibe right there π set it up once, get traits forever.
π¦ DESCRIPTION π¦
So basically this adds a COMPONENT method (as in Catalyst::Component) to your Catalyst component base class. That method reads the optional traits parameter from your app config and your component config, and then instantiates the component subclass with those traits using new_with_traits from MooseX::Traits via MooseX::Traits::Pluggable. no cap, that's it, that's the whole job π
π TRAIT SEARCH π
Trait names with a + in front? taken as full package names, periodt. no searching, no guessing, you said the whole thing, you meant the whole thing.
Unqualified names get searched for, using the algorithm below. it's giving detective energy π΅οΈβοΈ
πΈ EXAMPLE πΈ
say your inheritance hierarchy is:
MyApp::Model::MyModel
Catalyst::Model::CatModel
Catalyst::Model
Catalyst::Component
Moose::Object
and your config is:
traits => ['Foo']
then the package search order for Foo will be:
MyApp::TraitFor::Model::CatModel::Foo
Catalyst::TraitFor::Model::CatModel::Foo
see how it walked up the chain? yeah. iconic behavior β¨
π A MORE PATHOLOGICAL EXAMPLE π
okay now for the messy one. for:
My::App::Controller::AController
CatalystX::Something::ControllerBase::SomeController
Catalyst::Controller
Catalyst::Model
Catalyst::Component
Moose::Object
with:
traits => ['Foo']
the search order for Foo will be:
My::App::TraitFor::Controller::SomeController::Foo
CatalystX::Something::TraitFor::Controller::SomeController::Foo
and yeah β the Base after (M|V|C) gets automatically removed. the code said "not me reading 'ControllerBase' as 'Controller'" and just... fixed it. slay π
π«Ά TRAIT MERGING π«Ά
Traits from the component class config and the app config get automatically merged if you set the _trait_merge attribute default, like:
has '+_trait_merge' => (default => 1);
And you can also remove component class config traits by prefixing their names with a - in the app config traits. so rude, so effective π
for example:
package Catalyst::Model::Foo;
has '+_trait_merge' => (default => 1);
__PACKAGE__->config->{traits} = [qw/Foo Bar/];
package MyApp;
__PACKAGE__->config->{'Model::Foo'}{traits} = [qw/-Foo Baz/];
will load the traits:
Bar Baz
Foo said βοΈ and Baz said heyyy. the math is mathing π
π AUTHOR π
Rafael Kitover, <rkitover@cpan.org> β the main character who made this π
β CONTRIBUTORS β
Tomas Doran, <bobtfish@bobtfish.net> β bestie came through π«Ά
π BUGS π
Please report any bugs or feature requests to bug-catalystx-component-traits at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-Component-Traits>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so like... you WILL hear back. fr fr π€
π ACKNOWLEDGEMENTS π
Matt S. Trout and Tomas Doran helped me with the current design. the group project actually went well for once ππ
π COPYRIGHT & LICENSE π
Copyright (c) 2014, Rafael Kitover
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie β this is Cataly...Traits(3pm) from the User Contributed Perl Documentation, part of perl v5.34.0, dated 2022-06-09. go load some traits, you absolute icon π
β¨
π¦ where this page comes from
- debian bookworm: libcatalystx-component-traits-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libcatalystx-component-traits-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatalystx-component-traits-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalystx-component-traits-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalystx-component-traits-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms