Catalyst::Plugin::MapComponentDependencies::Utils - Utilities to integrate dependencies
package MyApp; use Moose; use Catalyst 'MapComponentDependencies; use Catalyst::Plugin::MapComponentDependencies::Utils ':All'; MyApp->config( 'Model::Bar' => { key => 'value' }, 'Model::Foo' => { bar => FromModel 'Bar', baz => FromCode { my ($app_or_ctx, $component_name) = @_; return ...; }, another_param => 'value', }, ); MyApp->setup;
Utility functions to streamline integration of dynamic dependencies into your global Catalyst configuration.
Catalyst::Plugin::MapComponentDependencies offers a simple way to specify configuration values for you components to be the value of other components and to do so in a way that respects if your component does ACCEPT_CONTEXT. We do this by providing a new namespace key in your configuration. However you may prefer a 'flatter' configuration. These utility methods allow you to 'tag' a value in your configuration. This leads to a more simple configuration setup, but it has the downside in that you must either use a Perl configuration (as in the SYNOPSIS example) or if you are using Catalyst::Plugin::ConfigLoader you can install additional configuration substitutions like so:
use Catalyst::Plugin::MapComponentDependencies::Utils ':All'; __PACKAGE__->config->{ 'Plugin::ConfigLoader' } ->{ substitutions } = { ConfigLoaderSubstitutions };
See Catalyst::Plugin::MapComponentDependencies for other options to declare your component dependencies if this approach does not appeal.
This package exports the following functions
Creates a dependency to the named model.
Creates a dependency to the named controller.
An anonymouse coderef that must return the expected dependency.
The current context, or undefined if the model does not ACCEPT_CONTEXT.
NOTE: Its really easy to create a circular reference when using the context as a dependency. I recommend making sure the object which is consuming it stores a weak reference. For example:
package MyApp::Object; use Moose; has ctx => (is=>'ro', required=>1, weak_ref=>1); # rest of code...
The current Catalyst::Request instance, or undefined if the model does not ACCEPT_CONTEXT.
The current Catalyst::Response instance, or undefined if the model does not ACCEPT_CONTEXT.
The current Log object.
You application class.
Returns a Hash suitable for use as additional substitutions in Catalyst::Plugin::ConfigLoader.
Catalyst, Catalyst::Plugin::MapComponentDependencies, Catalyst::Plugin::ConfigLoader.
John Napiorkowski email:jjnapiork@cpan.org
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.
To install Catalyst::Plugin::MapComponentDependencies, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::MapComponentDependencies
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::MapComponentDependencies
For more information on module installation, please visit the detailed CPAN module installation guide.