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" );
42 is_deeply( \@comps, \@loaded_comps, 'all components loaded' );
45 my @comps_copy = @comps;
47 my @controllers = map { s/^TestAppComponents::(C|Controller):://; $_; } @comps_copy[0..7];
48 my @models = map { s/^TestAppComponents::(M|Model):://; $_; } @comps_copy[8..15];
49 my @views = map { s/^TestAppComponents::(V|View):://; $_; } @comps_copy[16..23];
50 my $container = TestAppComponents->container;
53 [ sort $container->get_sub_container('controller')->get_service_list ],
54 [ sort @controllers ],
55 'controllers are in the container',
59 [ sort TestAppComponents->controllers ],
60 [ sort @controllers ],
61 'controllers are listed correctly by $c->controllers()',
65 [ sort $container->get_sub_container('model')->get_service_list ],
67 'models are in the container',
71 [ sort TestAppComponents->models ],
73 'models are listed correctly by $c->models()',
77 [ sort $container->get_sub_container('view')->get_service_list ],
79 'views are in the container',
83 [ sort TestAppComponents->views ],
85 'views are listed correctly by $c->views()',
89 [ sort keys %{ TestAppComponents->components } ],
91 'all components are in the components accessor'
96 sub overriden_locate_components {
98 push @comps, "TestAppComponents::$_" for qw/
102 C::Foo::Foo::Foo::Bar
103 Controller::Bar::Bar::Bar::Foo
104 Controller::Bar::Bar::Foo
110 M::Foo::Foo::Foo::Bar
111 Model::Bar::Bar::Bar::Foo
118 V::Foo::Foo::Foo::Bar
119 View::Bar::Bar::Bar::Foo