getting correct name for the component
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index 20ea288..921854c 100644 (file)
@@ -619,25 +619,10 @@ sub get_all_components {
         my $container = $self->get_sub_container($type);
 
         for my $component ($container->get_service_list) {
-            my $comp = $container->resolve(
-                service => $component
-            );
-            my $comp_name = ref $comp || $comp; # THIS IS WRONG! :)
-                                                # Just as it is called Model::Foo
-                                                # does not mean it has to be
-                                                # an instance of model::foo
-            # (AndrĂ©'s answer)
-            # t0m, you're absolutely right, I really hadn't thought about it.
-            # But then, we have a problem: suppose there is a component called
-            # MyApp::M::Foo, for instance. The service name would be 'Foo',
-            # and it would be stored in the 'model' sub container. So we have
-            # $app_name . '::' . uc_first($type) . '::' . $service_name
-            # that would return MyApp::Model::Foo. It would get really, really
-            # ugly to check MyApp::M::Foo. So, either we change the hash key,
-            # or we drop support for ::[CMV]::, or I don't know, maybe you
-            # have a better solution? :)
-
-            $components{$comp_name} = $comp;
+            my $comp = $container->get_service($component);
+
+            # is this better?
+            $components{$comp->catalyst_component_name} = $comp->get;
         }
     }
 
@@ -650,8 +635,6 @@ sub add_component {
 
     return unless $type;
 
-    my $component_service_name = "${type}_${name}";
-
     # The 'component' sub-container will create the object, and store it's
     # instance, which, by default, will live throughout the application.
     # The model/view/controller sub-containers only reference the instance
@@ -660,6 +643,12 @@ sub add_component {
     my $instance_container       = $self->get_sub_container('component');
     my $accept_context_container = $self->get_sub_container($type);
 
+    # Custom containers might have added the service already
+    # We don't want to override that
+    return if $accept_context_container->has_service( $name );
+
+    my $component_service_name = "${type}_${name}";
+
     $instance_container->add_service(
         Catalyst::IOC::ConstructorInjection->new(
             name      => $component_service_name,
@@ -670,9 +659,7 @@ sub add_component {
                 depends_on( '/application_name' ),
             ],
         )
-    ) unless $instance_container->has_service( $component_service_name );
-    # ^ custom containers might have added the service already.
-    # we don't want to override that.
+    );
 
     $accept_context_container->add_service(
         Catalyst::IOC::BlockInjection->new(
@@ -682,8 +669,7 @@ sub add_component {
             ],
             block => sub { shift->param($component_service_name) },
         )
-    ) unless $accept_context_container->has_service( $name );
-    # ^ same as above
+    );
 }
 
 # FIXME: should this sub exist?