1 package Catalyst::IOC::ConstructorInjection;
3 extends 'Bread::Board::ConstructorInjection';
5 with 'Bread::Board::Service::WithClass',
6 'Bread::Board::Service::WithDependencies',
7 'Bread::Board::Service::WithParameters',
8 'Catalyst::IOC::Service::WithAcceptContext';
10 sub _build_constructor_name { 'COMPONENT' }
15 my $constructor = $self->constructor_name;
16 my $component = $self->class;
17 my $params = $self->params;
18 my $config = $params->{config}->{ $self->param('suffix') } || {};
19 my $app_name = $params->{application_name};
21 unless ( $component->can( $constructor ) ) {
22 # FIXME - make some deprecation warnings
26 # Stash catalyst_component_name in the config here, so that custom COMPONENT
27 # methods also pass it. local to avoid pointlessly shitting in config
28 # for the debug screen, as $component is already the key name.
29 local $config->{catalyst_component_name} = $component;
31 my $instance = eval { $component->$constructor( $app_name, $config ) };
33 if ( my $error = $@ ) {
35 Catalyst::Exception->throw(
36 message => qq/Couldn't instantiate component "$component", "$error"/
39 elsif (!blessed $instance) {
40 my $metaclass = Moose::Util::find_meta($component);
41 my $method_meta = $metaclass->find_method_by_name('COMPONENT');
42 my $component_method_from = $method_meta->associated_metaclass->name;
43 my $value = defined($instance) ? $instance : 'undef';
44 Catalyst::Exception->throw(
46 qq/Couldn't instantiate component "$component", COMPONENT() method (from $component_method_from) didn't return an object-like value (value was $value)./
53 __PACKAGE__->meta->make_immutable;
63 Catalyst::IOC::BlockInjection
67 Catalyst Contributors, see Catalyst.pm
71 This library is free software. You can redistribute it and/or modify it under
72 the same terms as Perl itself.