Catalyst-Plugin-InjectionHelpers

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension Catalyst::Plugin::InjectionHelpers

0.015   06 August 2019
        - Fixed broken test case

0.014   29 January 2019
        - Fixed broken test case

0.013   22 January 2019
        - Document how to use this with Configloader so that injection
        overlays work as expected.

0.012   13 November 2018
        - Merged in experimental depenency injection support.
        - Breaking API change, see docs for backcompat wedge.

0.011   08 November 2018
        - Specify injection via '-inject' configuration key

0.010   21 August 2017
        - Application scope now inits its instance at setup time, not at

lib/Catalyst/Plugin/InjectionHelpers.pm  view on Meta::CPAN

            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

t/lib/MyApp/Controller/Root.pm  view on Meta::CPAN

use Moose;
use MooseX::MethodAttributes;
use Test::Most;

extends 'Catalyst::Controller';

sub test :Path(test) Args(0) {
  my ($self, $c) = @_;
  my $foo = $c->model('Foo');

  # Make sure configloader overlay is working
  is $foo->{bar}, 'baz';
  is ref($foo), 'MyApp::Dummy2';

  $c->response->body('test');
}

__PACKAGE__->config(namespace=>'');
__PACKAGE__->meta->make_immutable;



( run in 0.560 second using v1.01-cache-2.11-cpan-49f99fa48dc )