And works, with tests. 4 hours start to finish, that was fun :)
t0m [Thu, 23 Apr 2009 01:07:31 +0000 (02:07 +0100)]
lib/CatalystX/ModelToControllerReflector.pm
t/01app.t

index bfa9b93..59004e3 100644 (file)
@@ -5,9 +5,9 @@ use namespace::clean -except => 'meta';
 with 'CatalystX::DynamicComponent' 
     => { alias => { _setup_dynamic_component => '_setup_dynamic_controller' } };
 
-requires 'setup_actionts';
+requires 'setup_components';
 
-before 'setup_actions' => sub { shift->_setup_dynamic_controllers(@_); };
+after 'setup_components' => sub { shift->_setup_dynamic_controllers(@_); };
 
 sub _setup_dynamic_controllers {
     my ($app) = @_;
@@ -35,6 +35,8 @@ sub _reflect_model_to_controller {
     my $meta = $controller->meta;
     $meta->make_mutable; # Dirty, I should build the class, add the methods, then
                          # last of all make it a component
+    $meta->remove_method('COMPONENT');
+    $meta->superclasses('DynamicAppDemo::ControllerBase');
 
     my $methods = $model->meta->get_method_map;
     foreach my $method_name (keys %$methods) {
index edd83cd..9fbc5ed 100644 (file)
--- a/t/01app.t
+++ b/t/01app.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 3;
+use Test::More tests => 6;
 
 BEGIN { use_ok 'Catalyst::Test', 'DynamicAppDemo' }
 
@@ -10,3 +10,10 @@ BEGIN { use_ok 'Catalyst::Test', 'DynamicAppDemo' }
     is( $res->header('X-Foo'), 'bar', 'is calling correct code' );
 }
 
+{
+    my $res = request('/one/say_hello/world');
+    ok( $res->is_success, 'should succeed' );
+    is( $res->header('X-From-Model'), 'One' );
+    is( $res->header('X-From-Model-Data'), 'Hello world' ); 
+}
+