Created component sub-container, brought BlockInjection back
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / ConstructorInjection.pm
index e43b1cc..6474fd5 100644 (file)
@@ -2,48 +2,27 @@ package Catalyst::IOC::ConstructorInjection;
 use Moose;
 extends 'Bread::Board::ConstructorInjection';
 
-with 'Catalyst::IOC::Service::WithAcceptContext';
-
-sub _build_constructor_name { 'COMPONENT' }
+with 'Bread::Board::Service::WithClass',
+     'Bread::Board::Service::WithDependencies',
+     'Bread::Board::Service::WithParameters',
+     'Catalyst::IOC::Service::WithCOMPONENT';
 
+# FIXME - how much of this should move to ::WithCOMPONENT?
 sub get {
     my $self = shift;
 
     my $constructor = $self->constructor_name;
-    my $config      = $self->param('config')->{ $self->params->{suffix} } || {};
-    my $class       = $self->param('class');
     my $component   = $self->class;
-
-    unless ( $self->class->can( $constructor ) ) {
-        # FIXME - make some deprecation warnings
-        return $component;
-    }
+    my $params      = $self->params;
+    my $config      = $params->{config}->{ $self->param('suffix') } || {};
+    my $app_name    = $params->{application_name};
 
     # Stash catalyst_component_name in the config here, so that custom COMPONENT
     # methods also pass it. local to avoid pointlessly shitting in config
     # for the debug screen, as $component is already the key name.
-    local $config->{catalyst_component_name} = $self->class;
-
-    my $instance = eval { $component->$constructor( $class, $config ) };
-
-    if ( my $error = $@ ) {
-        chomp $error;
-        Catalyst::Exception->throw(
-            message => qq/Couldn't instantiate component "$component", "$error"/
-        );
-    }
-    elsif (!blessed $instance) {
-        my $metaclass = Moose::Util::find_meta($component);
-        my $method_meta = $metaclass->find_method_by_name('COMPONENT');
-        my $component_method_from = $method_meta->associated_metaclass->name;
-        my $value = defined($instance) ? $instance : 'undef';
-        Catalyst::Exception->throw(
-            message =>
-            qq/Couldn't instantiate component "$component", COMPONENT() method (from $component_method_from) didn't return an object-like value (value was $value)./
-        );
-    }
-
-    return $instance;
+    local $config->{catalyst_component_name} = $component;
+
+    return $component->$constructor( $app_name, $config );
 }
 
 __PACKAGE__->meta->make_immutable;
@@ -56,7 +35,11 @@ __END__
 
 =head1 NAME
 
-Catalyst::IOC::BlockInjection
+Catalyst::IOC::ConstructorInjection
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
 
 =head1 AUTHORS