it should at least compile
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index 1e9ec84..0635964 100644 (file)
@@ -151,6 +151,45 @@ sub build_component_subcontainer {
     );
 }
 
+sub build_home_service {
+    my $self = shift;
+
+    return Bread::Board::BlockInjection->new(
+        lifecycle => 'Singleton',
+        name => 'home',
+        block => sub {
+            my $self = shift;
+            my $class = $self->param('application_name');
+            my $home;
+
+            if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
+                $home = $env;
+            }
+
+            $home ||= Catalyst::Utils::home($class);
+
+            return $home;
+        },
+        dependencies => [ depends_on('application_name') ],
+    );
+}
+
+# FIXME: very ambiguous - maybe root_dir?
+sub build_root_service {
+    my $self = shift;
+
+    return Bread::Board::BlockInjection->new(
+        lifecycle => 'Singleton',
+        name => 'root',
+        block => sub {
+            my $self = shift;
+
+            return Path::Class::Dir->new( $self->param('home') )->subdir('root');
+        },
+        dependencies => [ depends_on('home') ],
+    );
+}
+
 sub build_application_name_service {
     my $self = shift;
 
@@ -465,6 +504,7 @@ sub setup_components {
     );
 
     if ($app_locate_components_addr != $cat_locate_components_addr) {
+        # FIXME - why not just say: @comps = $class->locate_components() ?
         $class->log->warn(qq{You have overridden locate_components. That } .
             qq{no longer works. Please refer to the documentation to achieve } .
             qq{similar results.\n}
@@ -682,8 +722,15 @@ sub add_component {
             dependencies => [
                 depends_on( '/application_name' ),
             ],
-        )
+        ),
     );
+    # XXX - FIXME - We have to explicitly build the service here,
+    #               causing the COMPONENT method to be called early here, as otherwise
+    #               if the component method defines other classes (e.g. the
+    #               ACCEPT_CONTEXT injection Model::DBIC::Schema does)
+    #               then they won't be found by Devel::InnerPackage
+    # see also t/aggregate/unit_core_component_loading.t
+    $instance_container->get_service($component_service_name)->get;
 
     $accept_context_container->add_service(
         Catalyst::IOC::BlockInjection->new(
@@ -735,20 +782,20 @@ Catalyst::Container - IOC for Catalyst components
 
 =head1 METHODS
 
-=head1 Building Containers
+=head1 Methods for Building Containers
 
 =head2 build_component_subcontainer
 
 Container that stores all components, i.e. all models, views and controllers
 together. Each service is an instance of the actual component, and by default
 it lives while the application is running. Retrieving components from this
-subcontainer will instantiate the component, if it hasn't been instantiated
+sub-container will instantiate the component, if it hasn't been instantiated
 already, but will not execute ACCEPT_CONTEXT.
 
 =head2 build_model_subcontainer
 
 Container that stores references for all models that are inside the components
-subcontainer. Retrieving a model triggers ACCEPT_CONTEXT, if it exists.
+sub-container. Retrieving a model triggers ACCEPT_CONTEXT, if it exists.
 
 =head2 build_view_subcontainer
 
@@ -758,7 +805,7 @@ Same as L<build_model_subcontainer>, but for views.
 
 Same as L<build_model_subcontainer>, but for controllers.
 
-=head1 Building Services
+=head1 Methods for Building Services
 
 =head2 build_application_name_service
 
@@ -809,7 +856,7 @@ Config::Any's available config file extensions (e.g. xml, json, pl, etc).
 
 =head2 build_prefix_service
 
-The prefix, based on the application name, that will be used to lookup the
+The prefix, based on the application name, that will be used to look-up the
 config files (which will be in the format $prefix.$extension). If the app is
 MyApp::Foo, the prefix will be myapp_foo.
 
@@ -886,7 +933,7 @@ to L<Module::Pluggable>.
 
 =head2 get_component_from_sub_container($sub_container, $name, $c, @args)
 
-Looks for components in a given subcontainer (such as controller, model or
+Looks for components in a given sub-container (such as controller, model or
 view), and returns the searched component. If $name is undef, it returns the
 default component (such as default_view, if $sub_container is 'view'). If
 $name is a regexp, it returns an array of matching components. Otherwise, it
@@ -895,19 +942,19 @@ looks for the component with name $name.
 =head2 get_all_components
 
 Fetches all the components, in each of the sub_containers model, view and
-controller, and returns a readonly hash. The keys are the class names, and
+controller, and returns a read-only hash. The keys are the class names, and
 the values are the blessed objects. This is what is returned by $c->components.
 
 =head2 add_component
 
-Adds a component to the appropriate subcontainer. The subcontainer is guessed
+Adds a component to the appropriate sub-container. The sub-container is guessed
 by the component name given.
 
 =head2 find_component
 
 Searches for components in all containers. If $component is the full class
-name, the subcontainer is guessed, and it gets the searched component in there.
-Otherwise, it looks for a component with that name in all subcontainers. If
+name, the sub-container is guessed, and it gets the searched component in there.
+Otherwise, it looks for a component with that name in all sub-containers. If
 $component is a regexp it calls _find_component_regexp and matches all
 components against that regexp.
 
@@ -918,6 +965,9 @@ is expected to return a list of component (package) names to be set up.
 
 =head2 setup_components
 
+Uses locate_components service to list the components, and adds them to the
+appropriate sub-containers, using add_component().
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm