4 use Bread::Board qw/depends_on/;
5 use Catalyst::IOC::ConstructorInjection;
7 use Sub::Exporter -setup => {
16 groups => { default => [qw/
31 ${"${caller}::customise_container"} = sub {
32 local ${"${caller}::current_container"} = shift;
37 sub model (&) { &_subcontainer }
38 sub view (&) { &_subcontainer }
39 sub controller (&) { &_subcontainer }
44 my ( $caller, $f, $l, $subcontainer ) = caller(1);
45 $subcontainer =~ s/^Catalyst::IOC:://;
48 local ${"${caller}::current_container"} =
49 ${"${caller}::current_container"}->get_sub_container($subcontainer);
54 my ($name, %args) = @_;
55 my $current_container;
60 $current_container = ${"${caller}::current_container"};
63 $args{dependencies} ||= {};
64 $args{dependencies}{catalyst_application} = depends_on( '/catalyst_application' );
66 my $lifecycle = $args{lifecycle} || 'Singleton';
67 $args{lifecycle} = grep( m/^$lifecycle$/, qw/COMPONENTSingleton Request/ )
68 ? "+Catalyst::IOC::LifeCycle::$lifecycle"
72 # FIXME - check $args{type} here!
74 my $component_name = join '::', (
75 $current_container->resolve(service => '/catalyst_application'),
76 ucfirst($current_container->name),
80 $current_container->add_service(
81 Catalyst::IOC::ConstructorInjection->new(
84 catalyst_component_name => $component_name,
97 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
101 package MyApp::Container;
104 extends 'Catalyst::IOC::Container';
111 # model Bar needs model Foo to be built before
112 # and Bar's constructor gets Foo as a parameter
113 component Bar => ( dependencies => [
114 depends_on('/model/Foo'),
117 # Baz is rebuilt once per HTTP request
118 component Baz => ( lifecycle => 'Request' );
120 # built only once per application life time
121 component Quux => ( lifecycle => 'Singleton' );
123 # built once per app life time and uses an external model,
124 # outside the default directory
125 # no need for wrappers or Catalyst::Model::Adaptor
127 lifecycle => 'Singleton',
128 class => 'My::External::Class',
132 component HTML => ();
135 component Root => ();
141 Catalyst::IOC provides "sugar" methods to extend the behavior of the default
148 Sets up the root container to be customised.
152 Sets up the model container to be customised.
156 Sets up the view container to be customised.
160 Sets up the controller container to be customised.
164 Adds a component to the sub-container. Works like L<Bread::Board::service>.
168 Catalyst Contributors, see Catalyst.pm
176 This library is free software. You can redistribute it and/or modify it under
177 the same terms as Perl itself.