Convert the two DynamicComponent clients to use the new protocol. This significantly...
t0m [Sun, 24 May 2009 23:41:20 +0000 (00:41 +0100)]
lib/CatalystX/ModelToControllerReflector.pm
lib/CatalystX/ModelsFromConfig.pm

index f81b5ba..69a7029 100644 (file)
@@ -6,6 +6,7 @@ use namespace::autoclean;
 
 with 'CatalystX::DynamicComponent' => {
     name => '_setup_dynamic_controller',
+    roles => ['CatalystX::ModelToControllerReflector::ControllerRole'],
 };
 
 requires 'setup_components';
@@ -43,10 +44,10 @@ sub _reflect_model_to_controller {
 
     my $config_name = $controller_name;
     $config_name =~ s/^[^:]+:://;
-    my $config = $app->config->{$config_name};
-    my @roles = @{ $config->{roles}||[] };
-    @roles = uniq @roles, 'CatalystX::ModelToControllerReflector::ControllerRole';
-    $config->{roles} = \@roles;
+    
+    # Shallow copy so we don't stuff method refs in config
+    my $config = { %{$app->config->{$config_name}} };
+    
     $config->{methods} = \%controller_methods;
     $app->_setup_dynamic_controller( $controller_name, $config );
 }
index d02e74e..edd1d46 100644 (file)
@@ -13,13 +13,15 @@ requires qw/
 #                       forced to do it globally.
 with 'CatalystX::DynamicComponent' => {
     name => '_setup_dynamic_model',
-    COMPONENT => sub {
-         my ($component_class_name, $app, $args) = @_;
+    methods => {
+        COMPONENT => sub {
+            my ($component_class_name, $app, $args) = @_;
 
-        my $class = delete $args->{class};
-        Class::MOP::load_class($class);
+            my $class = delete $args->{class};
+            Class::MOP::load_class($class);
 
-        $class->new($args);
+            $class->new($args);
+        },
     },
 };