From: André Walker Date: Wed, 25 Jul 2012 23:41:06 +0000 (-0300) Subject: moved setup_home to the container X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=1a5adaee236dda2152a9d0fb1ca27d08f3f92777 moved setup_home to the container --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 042e786..0e01305 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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'); } } diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index 535be3c..cb82f69 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -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') ], );