'Bread::Board::Service::WithParameters',
'Bread::Board::Service::WithDependencies';
-has config_key => (
+has config => (
is => 'ro',
- isa => 'Str',
- lazy_build => 1,
+ isa => 'HashRef',
+ required => 1,
);
-sub _build_config_key { Catalyst::Utils::class2classsuffix( shift->class ) }
-
-sub _build_constructor_name { 'COMPONENT' }
-
sub get {
my $self = shift;
- my $instance;
-
- my $constructor = $self->constructor_name;
my $component = $self->class;
- my %params = %{ $self->params };
- use Data::Dumper;
- Carp::cluck("Building $component with " . Dumper(\%params));
- my $config = delete($params{'config'})->{ $self->config_key } || {};
- %$config = (%$config, %params);
+ my %config = (%{ $self->config }, %{ $self->params });
# FIXME - Is depending on the application name to pass into constructors here a good idea?
# This makes app/ctx split harder I think.. Need to think more here, but I think
# Stash catalyst_component_name in the config here, so that custom COMPONENT
# methods also pass it. local to avoid pointlessly shitting in config
# for the debug screen, as $component is already the key name.
- local $config->{catalyst_component_name} = $component;
+ # XXX FIXME - WRONG!!! MyApp::Model::Foo may be an instance of something
+ # totally diferent, ergo it should get a catalyst_component_name
+ # of MyApp::Model::Foo.. Write failing tests for this in master?
+ $config{catalyst_component_name} = $component;
- unless ( $component->can( $constructor ) ) {
+ unless ( $component->can( 'COMPONENT' ) ) {
# FIXME - make some deprecation warnings
return $component;
}
+ my $instance;
try {
- $instance = $component->$constructor( $app_name, $config );
+ $instance = $component->COMPONENT( $app_name, \%config );
}
catch {
Catalyst::Exception->throw(
if blessed $instance;
my $metaclass = Moose::Util::find_meta($component);
- my $method_meta = $metaclass->find_method_by_name($constructor);
+ my $method_meta = $metaclass->find_method_by_name('COMPONENT');
my $component_method_from = $method_meta->associated_metaclass->name;
my $value = defined($instance) ? $instance : 'undef';
Catalyst::Exception->throw(
message =>
- qq/Couldn't instantiate component "$component", $constructor() method (from $component_method_from) didn't return an object-like value (value was $value)./
+ qq/Couldn't instantiate component "$component", COMPONENT method (from $component_method_from) didn't return an object-like value (value was $value)./
);
}
# sub every time they are called, when it exists.
my $instance_container = $self->get_sub_container('component');
my $accept_context_container = $self->get_sub_container($type);
+ my $app_config = $self->resolve( service => 'config' );
+ my $config = $app_config->{Catalyst::Utils::class2classsuffix($component)} || {};
$instance_container->add_service(
Catalyst::IOC::ConstructorInjection->new(
name => $component_service_name,
class => $component,
lifecycle => 'Singleton',
+ config => $config,
dependencies => [
depends_on( '/application_name' ),
- depends_on( '/config' ),
],
)
) unless $instance_container->has_service( $component_service_name );
my $self = shift;
warn("Add Bar to model");
+ my $bar_config = $self->resolve(service => 'config')->{'Model::Bar'} || {};
$self->get_sub_container('model')->add_service(
Catalyst::IOC::ConstructorInjection->new(
name => 'Bar',
lifecycle => 'Singleton',
class => 'TestAppCustomContainer::Model::Bar',
+ config => $bar_config,
dependencies => {
application_name => depends_on( '/application_name' ),
config => depends_on( '/config' ),
# )
# );
+ my $fnar_config = $self->resolve(service => 'config')->{'Model::Fnar'} || {};
$self->get_sub_container('component')->add_service(
Catalyst::IOC::ConstructorInjection->new(
name => 'model_Fnar',
class => 'TestAppCustomContainer::External::Class',
dependencies => [
depends_on( '/application_name' ),
- depends_on( '/config' ),
],
+ config => $fnar_config,
)
);
$self->get_sub_container('model')->add_service(