39e0c074864e71c13720fd9e815853aa659ffc6a
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / SugarContainer.pm
1 package TestAppCustomContainer::SugarContainer;
2 use Moose;
3 use namespace::autoclean;
4 use Catalyst::IOC;
5
6 extends 'Catalyst::IOC::Container';
7
8 # translate to sugar
9 sub BUILD {
10     my $self = shift;
11     $self->get_sub_container('component')->add_service(
12         Catalyst::IOC::ConstructorInjection->new(
13             name         => 'model_Baz',
14             class        => 'TestAppCustomContainer::Model::Baz',
15             lifecycle    => 'InstancePerContext',
16             dependencies => [
17                 depends_on( '/application_name' ),
18                 depends_on( '/config' ),
19                 depends_on( '/model/Foo' ),
20             ],
21         )
22     );
23     $self->get_sub_container('model')->add_service(
24         Catalyst::IOC::BlockInjection->new(
25             name         => 'Baz',
26             dependencies => [
27                 depends_on( '/model/Foo' ),
28                 depends_on( '/component/model_Baz' ),
29             ],
30             block => sub {
31                 my $s        = shift;
32                 my $foo      = $s->param('Foo');
33                 my $instance = $s->param('model_Baz');
34                 return $instance;
35             },
36         )
37     );
38 }
39
40 __PACKAGE__->meta->make_immutable;
41
42 1;