moved setup_home to the container
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index 0635964..cb82f69 100644 (file)
@@ -1,5 +1,5 @@
 package Catalyst::IOC::Container;
-use Bread::Board;
+use Bread::Board qw/depends_on/;
 use Moose;
 use Config::Any;
 use Data::Visitor::Callback;
@@ -41,12 +41,6 @@ has substitutions => (
     default => sub { +{} },
 );
 
-has application_name => (
-    is       => 'ro',
-    isa      => 'Str',
-    required => 1,
-);
-
 has sub_container_class => (
     isa     => LoadableClass,
     is      => 'ro',
@@ -66,7 +60,7 @@ sub BUILD {
         substitutions
         file
         driver
-        application_name
+        catalyst_application
         prefix
         extensions
         path
@@ -80,6 +74,8 @@ sub BUILD {
         config_local_suffix
         config_path
         locate_components
+        home
+        root_dir
     /;
 
     my $config = $self->resolve( service => 'config' );
@@ -158,29 +154,32 @@ sub build_home_service {
         lifecycle => 'Singleton',
         name => 'home',
         block => sub {
-            my $self = shift;
-            my $class = $self->param('application_name');
-            my $home;
+            my $self  = shift;
+            my $class = $self->param('catalyst_application');
 
             if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
-                $home = $env;
+                return $env;
             }
 
-            $home ||= Catalyst::Utils::home($class);
+            if ( my $home = $self->param('home_flag') ) {
+                return $home;
+            }
 
-            return $home;
+            return Catalyst::Utils::home($class);
+        },
+        parameters   => {
+            home_flag => { is => 'ro', isa => 'Str|Undef', required => 0 }
         },
-        dependencies => [ depends_on('application_name') ],
+        dependencies => [ depends_on('catalyst_application') ],
     );
 }
 
-# FIXME: very ambiguous - maybe root_dir?
-sub build_root_service {
+sub build_root_dir_service {
     my $self = shift;
 
     return Bread::Board::BlockInjection->new(
         lifecycle => 'Singleton',
-        name => 'root',
+        name => 'root_dir',
         block => sub {
             my $self = shift;
 
@@ -190,10 +189,10 @@ sub build_root_service {
     );
 }
 
-sub build_application_name_service {
+sub build_catalyst_application_service {
     my $self = shift;
 
-    return Bread::Board::Literal->new( name => 'application_name', value => $self->application_name );
+    return Bread::Board::Literal->new( name => 'catalyst_application', value => $self->name );
 }
 
 sub build_driver_service {
@@ -233,9 +232,9 @@ sub build_prefix_service {
         lifecycle => 'Singleton',
         name => 'prefix',
         block => sub {
-            return Catalyst::Utils::appprefix( shift->param('application_name') );
+            return Catalyst::Utils::appprefix( shift->param('catalyst_application') );
         },
-        dependencies => [ depends_on('application_name') ],
+        dependencies => [ depends_on('catalyst_application') ],
     );
 }
 
@@ -248,11 +247,11 @@ sub build_path_service {
         block => sub {
             my $s = shift;
 
-            return Catalyst::Utils::env_value( $s->param('application_name'), 'CONFIG' )
+            return Catalyst::Utils::env_value( $s->param('catalyst_application'), 'CONFIG' )
             || $s->param('file')
-            || $s->param('application_name')->path_to( $s->param('prefix') );
+            || $s->param('catalyst_application')->path_to( $s->param('prefix') );
         },
-        dependencies => [ depends_on('file'), depends_on('application_name'), depends_on('prefix') ],
+        dependencies => [ depends_on('file'), depends_on('catalyst_application'), depends_on('prefix') ],
     );
 }
 
@@ -268,13 +267,13 @@ sub build_config_service {
             my $v = Data::Visitor::Callback->new(
                 plain_value => sub {
                     return unless defined $_;
-                    return $self->_config_substitutions( $s->param('application_name'), $s->param('substitutions'), $_ );
+                    return $self->_config_substitutions( $s->param('catalyst_application'), $s->param('substitutions'), $_ );
                 }
 
             );
             $v->visit( $s->param('raw_config') );
         },
-        dependencies => [ depends_on('application_name'), depends_on('raw_config'), depends_on('substitutions') ],
+        dependencies => [ depends_on('catalyst_application'), depends_on('raw_config'), depends_on('substitutions') ],
     );
 }
 
@@ -366,7 +365,7 @@ sub build_class_config_service {
         name => 'class_config',
         block => sub {
             my $s   = shift;
-            my $app = $s->param('application_name');
+            my $app = $s->param('catalyst_application');
 
             # Container might be called outside Catalyst context
             return {} unless Class::MOP::is_class_loaded($app);
@@ -374,7 +373,7 @@ sub build_class_config_service {
             # config might not have been defined
             return $app->config || {};
         },
-        dependencies => [ depends_on('application_name') ],
+        dependencies => [ depends_on('catalyst_application') ],
     );
 }
 
@@ -451,11 +450,11 @@ sub build_config_local_suffix_service {
         name => 'config_local_suffix',
         block => sub {
             my $s = shift;
-            my $suffix = Catalyst::Utils::env_value( $s->param('application_name'), 'CONFIG_LOCAL_SUFFIX' ) || $self->config_local_suffix;
+            my $suffix = Catalyst::Utils::env_value( $s->param('catalyst_application'), 'CONFIG_LOCAL_SUFFIX' ) || $self->config_local_suffix;
 
             return $suffix;
         },
-        dependencies => [ depends_on('application_name') ],
+        dependencies => [ depends_on('catalyst_application') ],
     );
 }
 
@@ -467,7 +466,7 @@ sub build_locate_components_service {
         name      => 'locate_components',
         block     => sub {
             my $s      = shift;
-            my $class  = $s->param('application_name');
+            my $class  = $s->param('catalyst_application');
             my $config = $s->param('config')->{ setup_components };
 
             Catalyst::Exception->throw(
@@ -485,13 +484,13 @@ sub build_locate_components_service {
 
             return [ $locator->plugins ];
         },
-        dependencies => [ depends_on('application_name'), depends_on('config') ],
+        dependencies => [ depends_on('catalyst_application'), depends_on('config') ],
     );
 }
 
 sub setup_components {
     my $self = shift;
-    my $class = $self->resolve( service => 'application_name' );
+    my $class = $self->resolve( service => 'catalyst_application' );
     my @comps = @{ $self->resolve( service => 'locate_components' ) };
     my %comps = map { $_ => 1 } @comps;
     my $deprecatedcatalyst_component_names = 0;
@@ -720,7 +719,7 @@ sub add_component {
             class     => $component,
             lifecycle => 'Singleton',
             dependencies => [
-                depends_on( '/application_name' ),
+                depends_on( '/catalyst_application' ),
             ],
         ),
     );
@@ -766,6 +765,8 @@ sub expand_component_module {
     return Devel::InnerPackage::list_packages( $module );
 }
 
+__PACKAGE__->meta->make_immutable;
+
 1;
 
 __END__
@@ -807,10 +808,21 @@ Same as L<build_model_subcontainer>, but for controllers.
 
 =head1 Methods for Building Services
 
-=head2 build_application_name_service
+=head2 build_catalyst_application_service
 
 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.