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 my $lifecycle = $args{lifecycle};
69 my %catalyst_lifecycles = map { $_ => 1 } qw/ COMPONENTSingleton Request /;
70 $args{lifecycle} = $lifecycle
71 ? $catalyst_lifecycles{$lifecycle} ? "+Catalyst::IOC::LifeCycle::$lifecycle" : $lifecycle
75 # FIXME - check $args{type} here!
77 my $component_name = join '::', (
78 ${"${caller}::current_container"}->resolve(service => '/application_name'),
79 ucfirst(${"${caller}::current_container"}->name),
83 my $service = Catalyst::IOC::ConstructorInjection->new(
86 catalyst_component_name => $component_name,
88 ${"${caller}::current_container"}->add_service($service);
93 # FIXME - should the code example below be on this file or Catalyst::IOC::Container?
101 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
105 package MyApp::Container;
111 container $self => as {
112 container model => as {
117 # model Bar needs model Foo to be built before
118 # and Bar's constructor gets Foo as a parameter
119 component Bar => ( dependencies => [
120 depends_on('/model/Foo'),
123 # Baz is rebuilt once per HTTP request
124 component Baz => ( lifecycle => 'Request' );
126 # built only once per application life time
127 component Quux => ( lifecycle => 'Singleton' );
129 # built once per app life time and uses an external model,
130 # outside the default directory
131 # no need for wrappers or Catalyst::Model::Adaptor
133 lifecycle => 'Singleton',
134 class => 'My::External::Class',
146 Catalyst Contributors, see Catalyst.pm
154 This library is free software. You can redistribute it and/or modify it under
155 the same terms as Perl itself.