4 use Bread::Board qw/depends_on/;
5 use Catalyst::IOC::ConstructorInjection;
7 # FIXME - All of these imports need to get the importing package
8 # as the customise_container and current_container variables
9 # NEED to be in the containers package so there can be multiple
11 use Sub::Exporter -setup => {
18 groups => { default => [qw/
25 #use Sub::Exporter -setup => [
28 # Bread::Board::container
29 # Bread::Board::depends_on
30 # Bread::Board::service
32 # Bread::Board::wire_names
33 # Bread::Board::include
34 # Bread::Board::typemap
38 # I'm probably doing it wrong.
39 # Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter?
41 #Moose::Exporter->setup_import_methods(
42 # also => ['Bread::Board'],
44 our $customise_container;
45 our $current_container;
49 $customise_container = sub {
50 warn("In customise container");
51 local $current_container = shift();
58 local $current_container = $current_container->get_sub_container('model');
63 my ($name, %args) = @_;
64 $args{dependencies} ||= {};
65 $args{dependencies}{application_name} = depends_on( '/application_name' );
67 # FIXME - check $args{type} here!
69 my $component_name = join '::', (
70 $current_container->resolve(service => '/application_name'),
71 ucfirst($current_container->name),
75 my $service = Catalyst::IOC::ConstructorInjection->new(
78 lifecycle => 'Singleton',
79 # XX FIXME - needs to become possible to intuit catalyst_component_name
80 # from dependencies (like config)
81 catalyst_component_name => $component_name,
83 $current_container->add_service($service);
88 # FIXME - should the code example below be on this file or Catalyst::IOC::Container?
96 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
100 package MyApp::Container;
106 container $self => as {
107 container model => as {
112 # model Bar needs model Foo to be built before
113 # and Bar's constructor gets Foo as a parameter
114 component Bar => ( dependencies => [
115 depends_on('/model/Foo'),
118 # Baz is rebuilt once per HTTP request
119 component Baz => ( lifecycle => 'Request' );
121 # built only once per application life time
122 component Quux => ( lifecycle => 'Singleton' );
124 # built once per app life time and uses an external model,
125 # outside the default directory
126 # no need for wrappers or Catalyst::Model::Adaptor
128 lifecycle => 'Singleton',
129 class => 'My::External::Class',
141 Catalyst Contributors, see Catalyst.pm
149 This library is free software. You can redistribute it and/or modify it under
150 the same terms as Perl itself.