ditching the COMPONENT constructor
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / NoSugarContainer.pm
CommitLineData
88cea23c 1package TestAppCustomContainer::NoSugarContainer;
3ef84846 2use Moose;
88cea23c 3use namespace::autoclean;
4use Catalyst::IOC;
3ef84846 5
6extends 'Catalyst::IOC::Container';
7
8sub BUILD {
9 my $self = shift;
f831deb1 10
11 $self->get_sub_container('component')->add_service(
12 Catalyst::IOC::ConstructorInjection->new(
13 name => 'model_Bar',
fe3f6b6d 14 lifecycle => 'Singleton',
f831deb1 15 class => 'TestAppCustomContainer::Model::Bar',
16 dependencies => [
17 depends_on( '/application_name' ),
18 depends_on( '/config' ),
17f0d82d 19 depends_on( '/model/Foo' ),
f831deb1 20 ],
21 )
22 );
23 $self->get_sub_container('model')->add_service(
24 Catalyst::IOC::BlockInjection->new(
25 name => 'Bar',
e9af4f7d 26 lifecycle => 'Singleton',
f831deb1 27 dependencies => [
fe3f6b6d 28 Bread::Board::Dependency->new(
29 service_path => 'Foo',
c736869e 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?
fe3f6b6d 34 service_params => {
35 ctx => +{},
36 accept_context_args => [ +{} ],
37 },
38 ),
f831deb1 39 depends_on( '/component/model_Bar' ),
40 ],
41 block => sub {
b463fcad 42 my $s = shift;
43
44 my $foo = $s->param('Foo');
45 $foo->inc_bar_got_it;
46
47 return $s->param('model_Bar');
f831deb1 48 },
49 )
50 );
51
3ef84846 52 $self->get_sub_container('component')->add_service(
53 Catalyst::IOC::ConstructorInjection->new(
54 name => 'model_Baz',
88cea23c 55 class => 'TestAppCustomContainer::Model::Baz',
fe3f6b6d 56 lifecycle => 'Singleton',
c736869e 57
58 # while it doesn't fully work
fe3f6b6d 59 #lifecycle => '+Catalyst::IOC::LifeCycle::Request',
3ef84846 60 dependencies => [
61 depends_on( '/application_name' ),
62 depends_on( '/config' ),
17f0d82d 63 depends_on( '/model/Foo' ),
3ef84846 64 ],
65 )
66 );
67 $self->get_sub_container('model')->add_service(
68 Catalyst::IOC::BlockInjection->new(
69 name => 'Baz',
70 dependencies => [
fe3f6b6d 71 Bread::Board::Dependency->new(
72 service_path => 'Foo',
c736869e 73
74 # FIXME - same as above
fe3f6b6d 75 service_params => {
76 ctx => +{},
77 accept_context_args => [ +{} ],
78 },
79 ),
3ef84846 80 depends_on( '/component/model_Baz' ),
81 ],
82 block => sub {
b463fcad 83 my $s = shift;
84
85 my $foo = $s->param('Foo');
86 $foo->inc_baz_got_it;
87
88 return $s->param('model_Baz');
3ef84846 89 },
90 )
91 );
f831deb1 92
93 $self->get_sub_container('model')->add_service(
94 Catalyst::IOC::BlockInjection->new(
95 name => 'Quux',
f831deb1 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',
b463fcad 108 class => 'TestAppCustomContainer::External::Class',
f831deb1 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 );
3ef84846 126}
127
88cea23c 128__PACKAGE__->meta->make_immutable;
129
3ef84846 1301;