X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FIOC%2FContainer.pm;h=31dd7d6224cde6447a1ad93a82825a11d0247218;hb=efb195a58de076418b16547f3c2e35ee90812e8d;hp=8102262faf8c1777413db304aebe19979fb882b7;hpb=a987f40a116b21ecb196b0c43442499222e27507;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index 8102262..31dd7d6 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -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', @@ -151,10 +145,48 @@ 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; - return Bread::Board::Literal->new( name => 'application_name', value => $self->application_name ); + return Bread::Board::Literal->new( name => 'application_name', value => $self->name ); } sub build_driver_service { @@ -727,6 +759,8 @@ sub expand_component_module { return Devel::InnerPackage::list_packages( $module ); } +__PACKAGE__->meta->make_immutable; + 1; __END__