use Catalyst::IOC::ConstructorInjection;
no strict 'refs';
-# FIXME - All of these imports need to get the importing package
-# as the customise_container and current_container variables
-# NEED to be in the containers package so there can be multiple
-# containers..
use Sub::Exporter -setup => {
exports => [qw/
depends_on
container
/]},
};
-#use Sub::Exporter -setup => [
-# qw(
-# Bread::Board::as
-# Bread::Board::container
-# Bread::Board::depends_on
-# Bread::Board::service
-# Bread::Board::alias
-# Bread::Board::wire_names
-# Bread::Board::include
-# Bread::Board::typemap
-# Bread::Board::infer
-# )
-#];
-# I'm probably doing it wrong.
-# Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter?
-#use Moose::Exporter;
-#Moose::Exporter->setup_import_methods(
-# also => ['Bread::Board'],
-#);
+
sub container (&) {
my $code = shift;
my $caller = caller;
${"${caller}::customise_container"} = sub {
- warn("In customise container");
local ${"${caller}::current_container"} = shift;
$code->();
};
1;
-# FIXME - should the code example below be on this file or Catalyst::IOC::Container?
-
__END__
=pod
sub BUILD {
my $self = shift;
- $self->add_dependency(__catalyst_config => Bread::Board::Dependency->new(service_path => '/config'));
- warn("Added dependency for config in " . $self->class);
+ $self->add_dependency(
+ __catalyst_config => Bread::Board::Dependency->new(
+ service_path => '/config'
+ )
+ );
}
has catalyst_component_name => (
around resolve_dependencies => sub {
my ($orig, $self, @args) = @_;
my %deps = $self->$orig(@args);
-# use Data::Dumper;
-# warn("$self Resolve deps" . Data::Dumper::Dumper(\%deps));
my $app_config = delete $deps{__catalyst_config};
my $conf_key = Catalyst::Utils::class2classsuffix($self->catalyst_component_name);
$self->_set_config($app_config->{$conf_key} || {});
sub get {
my $self = shift;
my $component = $self->class;
- warn("In get $component");
my $params = $self->params;
my %config = (%{ $self->config || {} }, %{ $params });
-# warn(Data::Dumper::Dumper(\%config));
$self->_clear_config;
# FIXME - Is depending on the application name to pass into constructors here a good idea?
no strict 'refs';
no warnings 'once';
my $class = ref $self;
- warn("In build $class");
${ $class . '::customise_container' }->($self)
if ${ $class . '::customise_container' };
}
sub setup_components {
my $self = shift;
- warn("Setting up default components");
my $class = $self->resolve( service => 'application_name' );
my @comps = @{ $self->resolve( service => 'locate_components' ) };
my %comps = map { $_ => 1 } @comps;
for my $component ($container->get_service_list) {
my $comp_service = $container->get_service($component);
- warn "getting $component in $class, type $type";
-
$components{$comp_service->catalyst_component_name} = $comp_service->get(ctx => $class);
}
}
sub BUILD {
my $self = shift;
- warn("Add SingletonLifeCycle to model");
$self->get_sub_container('model')->add_service(
Catalyst::IOC::ConstructorInjection->new(
name => 'SingletonLifeCycle',
)
);
- warn("Add RequestLifeCycle to model");
$self->get_sub_container('model')->add_service(
Catalyst::IOC::ConstructorInjection->new(
name => 'RequestLifeCycle',
)
);
-# warn("Add DependsOnDefaultSetup to model");
# $self->get_sub_container('model')->add_service(
# Catalyst::IOC::ConstructorInjection->new(
# name => 'DependsOnDefaultSetup',