remove fixme
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index f8a9e97..fbc1a7d 100644 (file)
@@ -74,6 +74,8 @@ sub BUILD {
         config_local_suffix
         config_path
         locate_components
+        home
+        root_dir
     /;
 
     my $config = $self->resolve( service => 'config' );
@@ -152,16 +154,21 @@ sub build_home_service {
         lifecycle => 'Singleton',
         name => 'home',
         block => sub {
-            my $self = shift;
+            my $self  = shift;
             my $class = $self->param('catalyst_application');
-            my $home;
 
             if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
-                $home = $env;
+                return $env;
+            }
+
+            if ( my $home = $self->param('home_flag') ) {
+                return $home;
             }
 
-            $home ||= Catalyst::Utils::home($class);
-            return $home;
+            return Catalyst::Utils::home($class);
+        },
+        parameters   => {
+            home_flag => { is => 'ro', isa => 'Str|Undef', required => 0 }
         },
         dependencies => [ depends_on('catalyst_application') ],
     );
@@ -662,16 +669,80 @@ sub _find_component_regexp {
     return @result;
 }
 
+# FIXME
+# what exactly should this method return?
+# By default, for back-compatibility, we have two services for each component:
+#   - one in the model|view|controller sub-container
+#   - and another in the component sub-container
+# the latter is a Singleton, it executes the COMPONENT method, and the first
+# is executed at every call, executing ACCEPT_CONTEXT. It's just a layer.
+#
+# So the one in $type sub-container is pretty useless by default. But when the
+# user overrides the container (which is what we want), the sub-container they
+# will use is precisely $type, not 'component'. So for now, I'm returning both
+# services, to decide later what to do.
+sub get_all_component_services {
+    my $self = shift;
+
+    my %components;
+    my $components_container = $self->get_sub_container('component');
+
+    foreach my $type (qw/model view controller /) {
+        my $container = $self->get_sub_container($type);
+
+        for my $component ($container->get_service_list) {
+            my $comp_service = $container->get_service($component);
+
+            my $key    = $comp_service->catalyst_component_name;
+            my %values = (
+                type    => $type,
+                service => $comp_service,
+            );
+
+            my $comp_name = "${type}_${component}";
+            if ($components_container->has_service($comp_name)) {
+                $values{backcompat_service} = $components_container->get_service($comp_name);
+            }
+
+            $components{$key} = \%values;
+        }
+    }
+
+    return lock_hash %components;
+}
+
+sub get_all_singleton_lifecycle_components {
+    my $self = shift;
+
+    my %components;
+    my $components_container = $self->get_sub_container('component');
+
+    foreach my $type (qw/model view controller /) {
+        my $container = $self->get_sub_container($type);
+
+        for my $component ($container->get_service_list) {
+            my $comp_service = $container->get_service($component);
+
+            my $key       = $comp_service->catalyst_component_name;
+            my $lifecycle = $comp_service->lifecycle;
+            my $comp_name = "${type}_${component}";
+
+            if (defined $lifecycle && $lifecycle eq 'Singleton') {
+                $components{$key} = $comp_service->get;
+            }
+            elsif ($components_container->has_service($comp_name)) {
+                $components{$key} = $components_container->get_service($comp_name)->get;
+            }
+        }
+    }
+
+    return lock_hash %components;
+}
+
 sub get_all_components {
     my ($self, $class) = @_;
     my %components;
 
-    # FIXME - if we're getting from these containers, we need to either:
-    #   - pass 'ctx' and 'accept_context_args' OR
-    #   - make these params optional
-    # big problem when setting up the dispatcher - this method is called
-    # as $container->get_all_components('MyApp'). What to do with Request
-    # life cycles?
     foreach my $type (qw/model view controller /) {
         my $container = $self->get_sub_container($type);
 
@@ -805,6 +876,17 @@ Same as L<build_model_subcontainer>, but for controllers.
 
 Name of the application (such as MyApp).
 
+=head2 build_home_service
+
+The application home directory. All the files (including classes, scripts, etc)
+created for this application are in this directory, or in a sub-directory below
+this one.
+
+=head2 build_root_dir_service
+
+Inside the application home (as explained in L</build_home_service>), there is
+a root directory. This is where all templates and static files are.
+
 =head2 build_driver_service
 
 Config options passed directly to the driver being used.