4 use Moose::Meta::Class;
6 Moose::Meta::Class->create( TestAppComponents => (
7 superclasses => ['Catalyst'],
9 locate_components => \&overriden_locate_components,
13 TestAppComponents->components( {} );
15 # this is so TestAppComponents->container will work
16 TestAppComponents->setup_config;
18 # this is so TestAppComponents->log->warn will work
19 TestAppComponents->setup_log;
21 my @comps = TestAppComponents->locate_components;
23 for my $component (@comps) {
24 Moose::Meta::Class->create( $component => (
25 superclasses => ['Catalyst::Component'],
33 no warnings 'redefine', 'once';
35 local *Catalyst::Log::warn = sub { $warnings++ };
36 local *Catalyst::Utils::ensure_class_loaded = sub { my $class = shift; push @loaded_comps, $class; };
38 eval { TestAppComponents->setup_components };
40 ok( !$@, "setup_components doesnt die" );
41 ok( $warnings, "it warns about deprecated names" );
43 # FIXME - do I need the original sort in locate_components service?
44 is_deeply( [ sort @comps ], [ sort @loaded_comps ], 'all components loaded' );
47 my @comps_copy = @comps;
49 my @controllers = map { s/^TestAppComponents::(C|Controller):://; $_; } @comps_copy[0..7];
50 my @models = map { s/^TestAppComponents::(M|Model):://; $_; } @comps_copy[8..15];
51 my @views = map { s/^TestAppComponents::(V|View):://; $_; } @comps_copy[16..23];
52 my $container = TestAppComponents->container;
55 [ sort $container->get_sub_container('controller')->get_service_list ],
56 [ sort @controllers ],
57 'controllers are in the container',
61 [ sort TestAppComponents->controllers ],
62 [ sort @controllers ],
63 'controllers are listed correctly by $c->controllers()',
67 [ sort $container->get_sub_container('model')->get_service_list ],
69 'models are in the container',
73 [ sort TestAppComponents->models ],
75 'models are listed correctly by $c->models()',
79 [ sort $container->get_sub_container('view')->get_service_list ],
81 'views are in the container',
85 [ sort TestAppComponents->views ],
87 'views are listed correctly by $c->views()',
91 [ sort keys %{ TestAppComponents->components } ],
93 'all components are in the components accessor'
98 sub overriden_locate_components {
100 push @comps, "TestAppComponents::$_" for qw/
104 C::Foo::Foo::Foo::Bar
105 Controller::Bar::Bar::Bar::Foo
106 Controller::Bar::Bar::Foo
112 M::Foo::Foo::Foo::Bar
113 Model::Bar::Bar::Bar::Foo
120 V::Foo::Foo::Foo::Bar
121 View::Bar::Bar::Bar::Foo