NAME
Catalyst::Plugin::MapComponentDependencies - Allow components to depend on other components
SYNOPSIS
package MyApp;
use Moose;
use Catalyst;
with 'Catalyst::Plugin::MapComponentDependencies';
MyApp->map_dependencies(
'Model::Foo' => {
bar => 'Model::Bar',
baz => sub {
my ($app_or_ctx, $component_name) = @_;
return ...;
},
},
);
MyApp->config(
'Model::Foo' => { another_param => 'value' }
)
MyApp->setup;
During setup when 'Model::Foo' is created it will get all three key / value pairs send to ->new.
NOTE: You need to compose this plugin via the Moose 'with' subroutine if you want to get the handy class methods 'map_dependencies' and 'map_dependency'. If you prefer you may setup you dependencies via configuration:
package MyApp;
use Catalyst 'MapComponentDependencies';
MyApp->config(
'Model::Foo' => { another_param => 'value' },
'Plugin::MapComponentDependencies' => {
map_dependencies => {
'Model::Foo' => {
bar => 'Model::Bar',
baz => sub {
my ($app_or_ctx, $component_name) = @_;
return ...;
},
},
},
},
)
MyApp->setup;
You may prefer this if your dependencies will map differently based on environment and configuration settings.
DESCRIPTION
Sometimes you would like a Catalyst component to depend on the value of an existing component. Since components are resolved during application setup (or at request time, in the cause of a component that does ACCEPT_CONTEXT) you cannot specify this dependency mapping in the 'normal' Catalyst configuration hash.
This plugin, which requires a recent Catalyst of version 5.90090+, allows you to define components which depend on each other. You can also set the value of an initial argument to the value of a coderef, for added dynamic flexibility.
METHODS
This plugin defines the following methods
map_dependencies
Example:
MyApp->map_dependencies(
'Model::AnotherModel' => { aaa => 'Model::Foo' },
'Model::Foo' => {
bar => 'Model::Bar',
baz => sub {
my ($app_or_ctx, $component_name) = @_;
return ...;
},
},
);
Maps a list of components and dependencies
map_dependency
Maps a single component to a hashref of dependencies.
CONFIGURATION
This plugin defines the configuration namespace 'Plugin::MapComponentDependencies' and defines the following keys:
map_dependencies
A Hashref where the key is a target component and the value is a hashref of arguments that will be sent to it during initializion.
SEE ALSO
Catalyst, Catalyst::Plugin::InjectionHelpers.
AUTHOR
John Napiorkowski email:jjnapiork@cpan.org
COPYRIGHT & LICENSE
Copyright 2015, John Napiorkowski email:jjnapiork@cpan.org
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.