898296665b12f225486918368c8760f77e9b159d
[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                     service_params => {
30                         ctx => +{},
31                         accept_context_args => [ +{} ],
32                     },
33                 ),
34                 depends_on( '/component/model_Bar' ),
35             ],
36             block => sub {
37                 my $s   = shift;
38
39                 my $foo = $s->param('Foo');
40                 $foo->inc_bar_got_it;
41
42                 return $s->param('model_Bar');
43             },
44         )
45     );
46
47     $self->get_sub_container('component')->add_service(
48         Catalyst::IOC::ConstructorInjection->new(
49             name         => 'model_Baz',
50             class        => 'TestAppCustomContainer::Model::Baz',
51             lifecycle    => 'Singleton',
52             #lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
53             dependencies => [
54                 depends_on( '/application_name' ),
55                 depends_on( '/config' ),
56                 depends_on( 'model_Foo' ),
57             ],
58         )
59     );
60     $self->get_sub_container('model')->add_service(
61         Catalyst::IOC::BlockInjection->new(
62             name         => 'Baz',
63             dependencies => [
64                 Bread::Board::Dependency->new(
65                     service_path => 'Foo',
66                     service_params => {
67                         ctx => +{},
68                         accept_context_args => [ +{} ],
69                     },
70                 ),
71                 depends_on( '/component/model_Baz' ),
72             ],
73             block => sub {
74                 my $s   = shift;
75
76                 my $foo = $s->param('Foo');
77                 $foo->inc_baz_got_it;
78
79                 return $s->param('model_Baz');
80             },
81         )
82     );
83
84     $self->get_sub_container('model')->add_service(
85         Catalyst::IOC::BlockInjection->new(
86             name         => 'Quux',
87             lifecycle    => 'Singleton',
88             dependencies => [
89                 depends_on( '/component/model_Quux' ),
90             ],
91             block => sub { shift->param('model_Bar') },
92         )
93     );
94
95     $self->get_sub_container('component')->add_service(
96         Catalyst::IOC::ConstructorInjection->new(
97             name         => 'model_Fnar',
98             lifecycle    => 'Singleton',
99             class        => 'TestAppCustomContainer::External::Class',
100             dependencies => [
101                 depends_on( '/application_name' ),
102                 depends_on( '/config' ),
103             ],
104         )
105     );
106     $self->get_sub_container('model')->add_service(
107         Catalyst::IOC::BlockInjection->new(
108             name         => 'model_Fnar',
109             lifecycle    => 'Singleton',
110             dependencies => [
111                 depends_on( '/config' ),
112                 depends_on( '/component/model_Fnar' ),
113             ],
114             block => sub { shift->param('model_Fnar') },
115         )
116     );
117 }
118
119 __PACKAGE__->meta->make_immutable;
120
121 1;