Fix the logic somewhat
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / NoSugarContainer.pm
1 package TestAppCustomContainer::NoSugarContainer;
2 use Moose;
3 use namespace::autoclean;
4 use Catalyst::IOC;
5
6 extends 'Catalyst::IOC::Container';
7
8 sub BUILD {
9     my $self = shift;
10
11     $self->get_sub_container('model')->add_service(
12         Catalyst::IOC::ConstructorInjection->new(
13             name             => 'Bar',
14             lifecycle        => 'Singleton',
15             class            => 'TestAppCustomContainer::Model::Bar',
16             dependencies     => {
17                 application_name => depends_on( '/application_name' ),
18                 config => depends_on( '/config' ),
19                 foo => depends_on('/model/Foo'),
20             },
21         )
22     );
23
24     $self->get_sub_container('model')->add_service(
25         # FIXME - i think it should be a ConstructorInjection
26         # but only BlockInjection gets ctx parameter
27         Catalyst::IOC::BlockInjection->new(
28             name         => 'Baz',
29             lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
30             dependencies => [
31                 Bread::Board::Dependency->new(
32                     service_name => 'foo',
33                     service_path => 'Foo',
34
35                     # FIXME - same as above
36                     service_params => {
37                         ctx => +{},
38                         accept_context_args => [ +{} ],
39                     },
40                 ),
41             ],
42             block => sub {
43                 TestAppCustomContainer::Model::Baz->new(foo => shift->param('foo'));
44             },
45         )
46     );
47
48     $self->get_sub_container('model')->add_service(
49         Catalyst::IOC::BlockInjection->new(
50             name         => 'Quux',
51             lifecycle    => 'Singleton',
52             dependencies => [
53                 depends_on( '/component/model_Quux' ),
54             ],
55             block => sub { shift->param('model_Bar') },
56         )
57     );
58
59     $self->get_sub_container('component')->add_service(
60         Catalyst::IOC::ConstructorInjection->new(
61             name         => 'model_Fnar',
62             lifecycle    => 'Singleton',
63             class        => 'TestAppCustomContainer::External::Class',
64             dependencies => [
65                 depends_on( '/application_name' ),
66                 depends_on( '/config' ),
67             ],
68         )
69     );
70     $self->get_sub_container('model')->add_service(
71         Catalyst::IOC::BlockInjection->new(
72             name         => 'model_Fnar',
73             lifecycle    => 'Singleton',
74             dependencies => [
75                 depends_on( '/config' ),
76                 depends_on( '/component/model_Fnar' ),
77             ],
78             block => sub { shift->param('model_Fnar') },
79         )
80     );
81 }
82
83 __PACKAGE__->meta->make_immutable;
84
85 1;