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 @controllers = @comps[0..7];
46 my @models = @comps[8..15];
47 my @views = @comps[16..23];
48 my $container = TestAppComponents->container;
51 [ sort $container->get_sub_container('controller')->get_service_list ],
52 [ sort @controllers ],
53 'controllers are in the container',
57 [ sort TestAppComponents->controllers ],
58 [ sort @controllers ],
59 'controllers are listed correctly by $c->controllers()',
63 [ sort $container->get_sub_container('model')->get_service_list ],
65 'models are in the container',
69 [ sort TestAppComponents->models ],
71 'models are listed correctly by $c->models()',
75 [ sort $container->get_sub_container('view')->get_service_list ],
77 'views are in the container',
81 [ sort TestAppComponents->views ],
83 'views are listed correctly by $c->views()',
87 [ sort keys %{ TestAppComponents->components } ],
89 'all components are in the components accessor'
94 sub overriden_locate_components {
96 push @comps, "TestAppComponents::$_" for qw/
100 C::Foo::Foo::Foo::Bar
101 Controller::Bar::Bar::Bar::Foo
102 Controller::Bar::Bar::Foo
108 M::Foo::Foo::Foo::Bar
109 Model::Bar::Bar::Bar::Foo
116 V::Foo::Foo::Foo::Bar
117 View::Bar::Bar::Bar::Foo