Removed WithCOMPONENT, renamed My::External::Class
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / ConstructorInjection.pm
index 7a92087..0f112a0 100644 (file)
@@ -1,11 +1,19 @@
 package Catalyst::IOC::ConstructorInjection;
 use Moose;
+use Catalyst::Utils ();
 extends 'Bread::Board::ConstructorInjection';
 
 with 'Bread::Board::Service::WithClass',
-     'Bread::Board::Service::WithDependencies',
      'Bread::Board::Service::WithParameters',
-     'Catalyst::IOC::Service::WithAcceptContext';
+     'Bread::Board::Service::WithDependencies';
+
+has config_key => (
+    is         => 'ro',
+    isa        => 'Str',
+    lazy_build => 1,
+);
+
+sub _build_config_key { Catalyst::Utils::class2classsuffix( shift->class ) }
 
 sub _build_constructor_name { 'COMPONENT' }
 
@@ -14,20 +22,24 @@ sub get {
 
     my $constructor = $self->constructor_name;
     my $component   = $self->class;
-    my $params      = $self->params;
-    my $config      = $params->{config}->{ $self->param('suffix') } || {};
-    my $app_name    = $params->{application_name};
-
-    unless ( $component->can( $constructor ) ) {
-        # FIXME - make some deprecation warnings
-        return $component;
-    }
+    my $config      = $self->param('config')->{ $self->config_key } || {};
+    # FIXME - Is depending on the application name to pass into constructors here a good idea?
+    #         This makes app/ctx split harder I think.. Need to think more here, but I think
+    #         we want to pass the application in as a parameter when building the service
+    #         rather than depending on the app name, so that later, when the app becomes an instance
+    #         then it'll get passed in, and components can stash themselves 'per app instance'
+    my $app_name    = $self->param('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} = $component;
 
+    unless ( $component->can( $constructor ) ) {
+        # FIXME - make some deprecation warnings
+        return $component;
+    }
+
     my $instance = eval { $component->$constructor( $app_name, $config ) };
 
     if ( my $error = $@ ) {
@@ -38,12 +50,12 @@ sub get {
     }
     elsif (!blessed $instance) {
         my $metaclass = Moose::Util::find_meta($component);
-        my $method_meta = $metaclass->find_method_by_name('COMPONENT');
+        my $method_meta = $metaclass->find_method_by_name($constructor);
         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)./
+            qq/Couldn't instantiate component "$component", $constructor() method (from $component_method_from) didn't return an object-like value (value was $value)./
         );
     }
 
@@ -60,7 +72,11 @@ __END__
 
 =head1 NAME
 
-Catalyst::IOC::BlockInjection
+Catalyst::IOC::ConstructorInjection
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
 
 =head1 AUTHORS