added fixme's
[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->new(
13             name         => 'model_Bar',
14             lifecycle    => 'Singleton',
15             class        => 'TestAppCustomContainer::Model::Bar',
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         => 'Bar',
26             dependencies => [
27                 Bread::Board::Dependency->new(
28                     service_path => 'Foo',
29
30                     # FIXME - obviously this is a mistake
31                     # what to do with ctx here?
32                     # I have no way to get $s here, do I?
33                     service_params => {
34                         ctx => +{},
35                         accept_context_args => [ +{} ],
36                     },
37                 ),
38                 depends_on( '/component/model_Bar' ),
39             ],
40             block => sub {
41                 my $s   = shift;
42
43                 my $foo = $s->param('Foo');
44                 $foo->inc_bar_got_it;
45
46                 return $s->param('model_Bar');
47             },
48         )
49     );
50
51     $self->get_sub_container('component')->add_service(
52         Catalyst::IOC::ConstructorInjection->new(
53             name         => 'model_Baz',
54             class        => 'TestAppCustomContainer::Model::Baz',
55             lifecycle    => 'Singleton',
56
57             # while it doesn't fully work
58             #lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
59             dependencies => [
60                 depends_on( '/application_name' ),
61                 depends_on( '/config' ),
62                 depends_on( 'model_Foo' ),
63             ],
64         )
65     );
66     $self->get_sub_container('model')->add_service(
67         Catalyst::IOC::BlockInjection->new(
68             name         => 'Baz',
69             dependencies => [
70                 Bread::Board::Dependency->new(
71                     service_path => 'Foo',
72
73                     # FIXME - same as above
74                     service_params => {
75                         ctx => +{},
76                         accept_context_args => [ +{} ],
77                     },
78                 ),
79                 depends_on( '/component/model_Baz' ),
80             ],
81             block => sub {
82                 my $s   = shift;
83
84                 my $foo = $s->param('Foo');
85                 $foo->inc_baz_got_it;
86
87                 return $s->param('model_Baz');
88             },
89         )
90     );
91
92     $self->get_sub_container('model')->add_service(
93         Catalyst::IOC::BlockInjection->new(
94             name         => 'Quux',
95             lifecycle    => 'Singleton',
96             dependencies => [
97                 depends_on( '/component/model_Quux' ),
98             ],
99             block => sub { shift->param('model_Bar') },
100         )
101     );
102
103     $self->get_sub_container('component')->add_service(
104         Catalyst::IOC::ConstructorInjection->new(
105             name         => 'model_Fnar',
106             lifecycle    => 'Singleton',
107             class        => 'TestAppCustomContainer::External::Class',
108             dependencies => [
109                 depends_on( '/application_name' ),
110                 depends_on( '/config' ),
111             ],
112         )
113     );
114     $self->get_sub_container('model')->add_service(
115         Catalyst::IOC::BlockInjection->new(
116             name         => 'model_Fnar',
117             lifecycle    => 'Singleton',
118             dependencies => [
119                 depends_on( '/config' ),
120                 depends_on( '/component/model_Fnar' ),
121             ],
122             block => sub { shift->param('model_Fnar') },
123         )
124     );
125 }
126
127 __PACKAGE__->meta->make_immutable;
128
129 1;