NAME
Catalyst::Plugin::MapComponentDependencies::Utils - Utilities to integrate dependencies
SYNOPSIS
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;
DESCRIPTION
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.
EXPORTS
This package exports the following functions
FromModel
Creates a dependency to the named model.
FromView
Creates a dependency to the named model.
FromController
Creates a dependency to the named controller.
FromCode
An anonymouse coderef that must return the expected dependency.
FromContext
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...
FromRequest
The current Catalyst::Request instance, or undefined if the model does not ACCEPT_CONTEXT.
FromResponse
The current Catalyst::Response instance, or undefined if the model does not ACCEPT_CONTEXT.
FromLog
The current Log object.
FromApplication
You application class.
ConfigLoaderSubstitutions
Returns a Hash suitable for use as additional substitutions in Catalyst::Plugin::ConfigLoader.
SEE ALSO
Catalyst, Catalyst::Plugin::MapComponentDependencies, Catalyst::Plugin::ConfigLoader.
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.