use strict;
use warnings;
use Bread::Board;
+use Catalyst::IOC::ConstructorInjection;
# FIXME - neither of these work:
-#use Sub::Exporter -setup => [
-# qw(
-# as
-# container
-# depends_on
-# service
-# alias
-# wire_names
-# include
-# typemap
-# infer
-# )
-#];
+use Sub::Exporter -setup => {
+ exports => [qw/
+ component
+ /],
+ groups => { default => [qw/
+ component
+ /]},
+};
#use Sub::Exporter -setup => [
# qw(
# Bread::Board::as
#];
# 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'],
-);
+#use Moose::Exporter;
+#Moose::Exporter->setup_import_methods(
+# also => ['Bread::Board'],
+#);
+
+sub component {
+ my ($name, %args) = @_;
+ $args{dependencies} ||= {};
+ $args{dependencies}{application_name} = depends_on( '/application_name' );
+
+ # FIXME - check $args{type} here!
+
+ Catalyst::IOC::ConstructorInjection->new(
+ %args,
+ name => $name,
+ lifecycle => 'Singleton',
+ # XX FIXME - needs to become possible to intuit catalyst_component_name
+ # from dependencies (like config)
+ catalyst_component_name => 'TestAppCustomContainer::Model::Bar',
+ )
+}
1;
use Moose;
use namespace::autoclean;
use Catalyst::IOC;
-
+use Bread::Board;
extends 'Catalyst::IOC::Container';
sub BUILD {
my $self = shift;
- container $self => as {
- container model => as {
- component Foo => ();
- component Bar => ( dependencies => [ depends_on('/model/Foo') ] );
- component Baz => (
- lifecycle => '+Catalyst::IOC::LifeCycle::Request',
- dependencies => [
- depends_on( '/application_name' ),
- depends_on( '/config' ),
- depends_on( '/model/Foo' ),
- ],
- );
- component Quux => ( lifecycle => 'Singleton' );
- component Fnar => (
- lifecycle => 'Singleton',
- class => 'My::External::Class',
- dependencies => [ depends_on('config') ],
- # ^^ FIXME - gets whole config, not Model::Foo
- # There should be a 'nice' way to get the 'standard' config
- );
- };
- };
+ warn("Add Bar to model");
+ $self->get_sub_container('model')->add_service(
+ component(
+ 'Bar' =>
+ class => 'TestAppCustomContainer::Model::Bar',
+ dependencies => { foo => depends_on('/model/DefaultSetup') },
+ )
+ );
}
__PACKAGE__->meta->make_immutable;