FIXME's and comments
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index 30a7a77..20ea288 100644 (file)
@@ -443,6 +443,7 @@ sub build_locate_components_service {
 
 sub setup_components {
     my $self = shift;
+    warn("Setting up default components");
     my $class = $self->resolve( service => 'application_name' );
     my @comps = @{ $self->resolve( service => 'locate_components' ) };
     my %comps = map { $_ => 1 } @comps;
@@ -611,14 +612,33 @@ sub get_all_components {
     my $self = shift;
     my %components;
 
-    my $container = $self->get_sub_container('component');
+    # FIXME - if we're getting from these containers, we need to either:
+    #   - pass 'ctx' and 'accept_context_args' OR
+    #   - make these params optional
+    foreach my $type (qw/model view controller /) {
+        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;
-        $components{$comp_name} = $comp;
+        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;
+        }
     }
 
     return lock_hash %components;
@@ -643,11 +663,11 @@ sub add_component {
     $instance_container->add_service(
         Catalyst::IOC::ConstructorInjection->new(
             name      => $component_service_name,
+            catalyst_component_name => $component,
             class     => $component,
             lifecycle => 'Singleton',
             dependencies => [
                 depends_on( '/application_name' ),
-                depends_on( '/config' ),
             ],
         )
     ) unless $instance_container->has_service( $component_service_name );