made tests pass, spreading FIXME's all over the place
[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('component')->add_service(
12         # Catalyst::IOC::ConstructorInjection gives the constructor the wrong
13         # parameters
14         Bread::Board::ConstructorInjection->new(
15             name             => 'model_Bar',
16             lifecycle        => 'Singleton',
17             class            => 'TestAppCustomContainer::Model::Bar',
18             constructor_name => 'new',
19             dependencies     => {
20                 application_name => depends_on( '/application_name' ),
21                 config => depends_on( '/config' ),
22                 foo => Bread::Board::Dependency->new(
23                     service_name => 'foo',
24                     service_path => '/model/Foo',
25
26                     # FIXME - obviously this is a mistake
27                     # what to do with ctx here?
28                     # I have no way to get $s here, do I?
29                     service_params => {
30                         ctx => +{},
31                         accept_context_args => [ +{} ],
32                     },
33                 ),
34             },
35         )
36     );
37     $self->get_sub_container('model')->add_service(
38         Catalyst::IOC::BlockInjection->new(
39             name         => 'Bar',
40             lifecycle    => 'Singleton',
41             dependencies => [
42                 depends_on( '/component/model_Bar' ),
43             ],
44             block => sub {
45                 shift->param('model_Bar');
46             },
47         )
48     );
49
50     # FIXME - this is to avoid the default service to be added
51     # if that happened, the app would die
52     $self->get_sub_container('component')->add_service(
53         service model_Baz => 'TestAppCustomContainer::Model::Baz',
54     );
55     $self->get_sub_container('model')->add_service(
56         # FIXME - i think it should be a ConstructorInjection
57         # but only BlockInjection gets ctx parameter
58         Catalyst::IOC::BlockInjection->new(
59             name         => 'Baz',
60             lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
61             dependencies => [
62                 Bread::Board::Dependency->new(
63                     service_name => 'foo',
64                     service_path => 'Foo',
65
66                     # FIXME - same as above
67                     service_params => {
68                         ctx => +{},
69                         accept_context_args => [ +{} ],
70                     },
71                 ),
72             ],
73             block => sub {
74                 TestAppCustomContainer::Model::Baz->new(foo => shift->param('foo'));
75             },
76         )
77     );
78
79     $self->get_sub_container('model')->add_service(
80         Catalyst::IOC::BlockInjection->new(
81             name         => 'Quux',
82             lifecycle    => 'Singleton',
83             dependencies => [
84                 depends_on( '/component/model_Quux' ),
85             ],
86             block => sub { shift->param('model_Bar') },
87         )
88     );
89
90     $self->get_sub_container('component')->add_service(
91         Catalyst::IOC::ConstructorInjection->new(
92             name         => 'model_Fnar',
93             lifecycle    => 'Singleton',
94             class        => 'TestAppCustomContainer::External::Class',
95             dependencies => [
96                 depends_on( '/application_name' ),
97                 depends_on( '/config' ),
98             ],
99         )
100     );
101     $self->get_sub_container('model')->add_service(
102         Catalyst::IOC::BlockInjection->new(
103             name         => 'model_Fnar',
104             lifecycle    => 'Singleton',
105             dependencies => [
106                 depends_on( '/config' ),
107                 depends_on( '/component/model_Fnar' ),
108             ],
109             block => sub { shift->param('model_Fnar') },
110         )
111     );
112 }
113
114 __PACKAGE__->meta->make_immutable;
115
116 1;