4 use Test::More tests => 10;
8 BEGIN { use_ok('CatalystX::DynamicComponent') }
10 my $testapp_counter = 0;
11 sub generate_testapp {
12 my $role_options = shift || {};
13 my $meta = Moose->init_meta( for_class => "TestApp" . $testapp_counter++ );
14 $meta->superclasses('Catalyst');
15 Moose::Util::apply_all_roles($meta, 'CatalystX::DynamicComponent', $role_options);
20 throws_ok { generate_testapp(); }
21 qr/name\) is required/, 'name is required';
24 my $app_meta = generate_testapp({ name => 'dynamic_component_method' });
25 my $app = $app_meta->name;
26 ok $app->can('dynamic_component_method'), 'dynamic component method added';
27 $app->dynamic_component_method( $app . "::Model::Foo", {} );
28 my $foo = $app->model('Foo');
29 ok $foo, 'Have added Foo component';
30 isa_ok($foo, 'Catalyst::Component');
34 my $COMPONENT = sub { return bless {}, 'TestClass' };
35 my $app_meta = generate_testapp({
36 name => 'dynamic_component_method',
37 COMPONENT => $COMPONENT,
39 my $app = $app_meta->name;
40 ok $app->can('dynamic_component_method'), 'dynamic component method added';
41 $app->dynamic_component_method( $app . "::Model::Foo", {} );
42 my $foo = $app->model('Foo');
43 ok $foo, 'Have added Foo component';
44 isa_ok($foo, 'TestClass', 'COMPONENT method returned totally different class');
45 my $name = $app . "::Model::Foo";
46 isa_ok(bless({}, $name), 'Catalyst::Component', 'Underlying $app::Model::Foo is a C::C');
47 is($name->can('COMPONENT'), $COMPONENT, 'Supplied COMPONENT method is on $app::Model::Foo');