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