moved setup_home to the container
André Walker [Wed, 25 Jul 2012 23:41:06 +0000 (20:41 -0300)]
lib/Catalyst.pm
lib/Catalyst/IOC/Container.pm

index 042e786..0e01305 100644 (file)
@@ -131,6 +131,13 @@ sub import {
     }
 
     $caller->arguments( [@arguments] );
+
+    # FIXME
+    # what is this for?
+    # we call setup_home on import AND on ->setup
+    # is there a reason for it?
+    # anyway there is no point for setup_home without setup_config() so...
+    $caller->setup_config;
     $caller->setup_home;
 }
 
@@ -2599,18 +2606,19 @@ Sets up the home directory.
 =cut
 
 sub setup_home {
-    my ( $class, $home ) = @_;
-
-    if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
-        $home = $env;
-    }
+    my ( $class, $home_flag ) = @_;
 
-    $home ||= Catalyst::Utils::home($class);
+    my $home = $class->container->resolve(
+        service    => 'home',
+        parameters => {
+            home_flag => $home_flag
+        },
+    );
 
     if ($home) {
         #I remember recently being scolded for assigning config values like this
         $class->config->{home} ||= $home;
-        $class->config->{root} ||= Path::Class::Dir->new($home)->subdir('root');
+        $class->config->{root} ||= $class->container->resolve(service => 'root_dir');
     }
 }
 
index 535be3c..cb82f69 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') ],
     );