4 use Bread::Board qw/depends_on/;
5 use Catalyst::IOC::ConstructorInjection;
8 # FIXME - All of these imports need to get the importing package
9 # as the customise_container and current_container variables
10 # NEED to be in the containers package so there can be multiple
12 use Sub::Exporter -setup => {
19 groups => { default => [qw/
26 #use Sub::Exporter -setup => [
29 # Bread::Board::container
30 # Bread::Board::depends_on
31 # Bread::Board::service
33 # Bread::Board::wire_names
34 # Bread::Board::include
35 # Bread::Board::typemap
39 # I'm probably doing it wrong.
40 # Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter?
42 #Moose::Exporter->setup_import_methods(
43 # also => ['Bread::Board'],
48 ${"${caller}::customise_container"} = sub {
49 warn("In customise container");
50 local ${"${caller}::current_container"} = shift;
58 local ${"${caller}::current_container"} = ${"${caller}::current_container"}->get_sub_container('model');
63 my ($name, %args) = @_;
65 $args{dependencies} ||= {};
66 $args{dependencies}{application_name} = depends_on( '/application_name' );
68 # FIXME - check $args{type} here!
70 my $component_name = join '::', (
71 ${"${caller}::current_container"}->resolve(service => '/application_name'),
72 ucfirst(${"${caller}::current_container"}->name),
76 my $service = Catalyst::IOC::ConstructorInjection->new(
79 lifecycle => 'Singleton',
80 # XX FIXME - needs to become possible to intuit catalyst_component_name
81 # from dependencies (like config)
82 catalyst_component_name => $component_name,
84 ${"${caller}::current_container"}->add_service($service);
89 # FIXME - should the code example below be on this file or Catalyst::IOC::Container?
97 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
101 package MyApp::Container;
107 container $self => as {
108 container model => as {
113 # model Bar needs model Foo to be built before
114 # and Bar's constructor gets Foo as a parameter
115 component Bar => ( dependencies => [
116 depends_on('/model/Foo'),
119 # Baz is rebuilt once per HTTP request
120 component Baz => ( lifecycle => 'Request' );
122 # built only once per application life time
123 component Quux => ( lifecycle => 'Singleton' );
125 # built once per app life time and uses an external model,
126 # outside the default directory
127 # no need for wrappers or Catalyst::Model::Adaptor
129 lifecycle => 'Singleton',
130 class => 'My::External::Class',
142 Catalyst Contributors, see Catalyst.pm
150 This library is free software. You can redistribute it and/or modify it under
151 the same terms as Perl itself.