Catalyst-Plugin-InjectionHelpers
view release on metacpan or search on metacpan
lib/Catalyst/Plugin/InjectionHelpers.pm view on Meta::CPAN
=head2 default_adaptor
The default adaptor to use, should you not set one. Defaults to 'Application'.
=head2 dispatchers
Allows you to add to the default dependency injection handers:
MyApp->config(
'Plugin::InjectionHelpers' => {
dispatchers => {
'-my' => sub {
my ($app_ctx, $what) = @_;
warn "asking for a -my $what";
return ....;
},
},
},
# Rest of configuration
);
=head2 version
Default is 2. Set to 1 if you are need compatibility version 0.011 or older
style of arguments for 'method' and 'from_code'.
=head1 Catalyst::Plugin::ConfigLoader
When using this plugin with L<Catalyst::Plugin::ConfigLoader> you should add it to the
plugin list afterward, for example:
package MyApp;
use Catalyst 'ConfigLoader',
'InjectionHelpers';
Please keep in mind that due to the way Configloader merges the configuration files
you might have to set some things to C<undef> in order to get the correct behavior. For
example you might define a model by default using from_code:
package MyApp;
use Catalyst 'ConfigLoader',
'InjectionHelpers';
MyApp->config(
'Model::Foo' => {
-inject => {
from_code => sub {
my ($app, %args) = @_;
return bless +{ %args, app=>$app }, 'Dummy1';
},
},
bar => 'baz',
},
);
MyApp->setup;
But then in youe configuration file overlay, you want to specify a class. In that case you
will need to undefine the default keys:
# File:myapp_local.pl
return +{
'Model::Foo' => {
-inject => {
from_class => 'MyApp::Dummy2',
from_code => undef, # Need to blow away the existing...
},
},
};
Its probably not ideal that the configuration overlay doesn't permit you to tag refs as 'replace'
rather than 'merge' but this is not a problem with this plugin. If it bothers you that a
configuration overlay would require to have understanding of how 'lower' configurations are setup
you should be able to avoid it by using all the same keys.
=head1 PRIOR ART
You may wish to review other similar approach on CPAN:
L<Catalyst::Model::Adaptor>.
=head1 AUTHOR
John Napiorkowski L<email:jjnapiork@cpan.org>
=head1 SEE ALSO
L<Catalyst>, L<Catalyst::Model::InjectionHelpers::Application>,
L<Catalyst::Model::InjectionHelpers::Factory>, L<Catalyst::Model::InjectionHelpers::PerRequest>
L<Catalyst::ModelRole::InjectionHelpers>
=head1 COPYRIGHT & LICENSE
Copyright 2016, John Napiorkowski L<email:jjnapiork@cpan.org>
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
( run in 1.670 second using v1.01-cache-2.11-cpan-d7f47b0818f )