package Catalyst::IOC::Container;
-use Bread::Board;
+use Bread::Board qw/depends_on/;
use Moose;
use Config::Any;
use Data::Visitor::Callback;
extends 'Bread::Board::Container';
+has flags => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ default => sub { [] },
+);
+
has config_local_suffix => (
is => 'ro',
isa => 'Str',
default => sub { +{} },
);
-has application_name => (
- is => 'ro',
- isa => 'Str',
- required => 1,
-);
-
has sub_container_class => (
isa => LoadableClass,
is => 'ro',
substitutions
file
driver
- application_name
+ catalyst_application
prefix
extensions
path
config_local_suffix
config_path
locate_components
+ flags
+ home
+ root_dir
/;
my $config = $self->resolve( service => 'config' );
);
}
+sub build_flags_service {
+ my $self = shift;
+
+ return Bread::Board::Literal->new(
+ lifecycle => 'Singleton',
+ name => 'flags',
+ value => $self->get_flags,
+ );
+}
+
+sub get_flags {
+ my $self = shift;
+ my $flags = {};
+
+ foreach (@{ $self->flags }) {
+ if (/^-Debug$/) {
+ $flags->{log} =
+ ( $flags->{log} ) ? 'debug,' . $flags->{log} : 'debug';
+ }
+ elsif (/^-(\w+)=?(.*)$/) {
+ $flags->{ lc $1 } = $2;
+ }
+ else {
+ push @{ $flags->{plugins} }, $_;
+ }
+ }
+
+ return $flags;
+}
+
sub build_home_service {
my $self = shift;
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);
- return $home;
+ if ( my $home = $self->param('flags')->{home} ) {
+ return $home;
+ }
+
+ return Catalyst::Utils::home($class);
},
- dependencies => [ depends_on('application_name') ],
+ dependencies => [ depends_on('flags'), 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;
);
}
-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 {
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') ],
);
}
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') ],
);
}
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') ],
);
}
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);
# config might not have been defined
return $app->config || {};
},
- dependencies => [ depends_on('application_name') ],
+ dependencies => [ depends_on('catalyst_application') ],
);
}
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') ],
);
}
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(
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;
class => $component,
lifecycle => 'Singleton',
dependencies => [
- depends_on( '/application_name' ),
+ depends_on( '/catalyst_application' ),
],
),
);
return Devel::InnerPackage::list_packages( $module );
}
+__PACKAGE__->meta->make_immutable;
+
1;
__END__
=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.