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