Make superclasses and roles tests pass
Tomas Doran (t0m) [Sat, 23 May 2009 19:55:49 +0000 (20:55 +0100)]
lib/CatalystX/DynamicComponent.pm
lib/CatalystX/ModelToControllerReflector.pm
t/lib/DynamicAppDemo.pm

index 39276c4..33c4e29 100644 (file)
@@ -1,21 +1,22 @@
 package CatalystX::DynamicComponent;
 use MooseX::Role::Parameterized;
+use MooseX::Types::Moose qw/Str CodeRef ArrayRef/;
 use namespace::autoclean;
 
 our $VERSION = 0.000001;
 
 parameter 'name' => (
-    isa => 'Str',
+    isa => Str,
     required => 1,
 );
 
 parameter 'pre_immutable_hook' => (
-    isa => 'Str',
+    isa => Str,
     predicate => 'has_pre_immutable_hook',
 );
 
 parameter 'COMPONENT' => (
-    isa => 'CodeRef',
+    isa => CodeRef,
     predicate => 'has_custom_component_method',
 );
 
@@ -23,6 +24,7 @@ role {
     my $p = shift;
     my $name = $p->name;
     my $pre_immutable_hook = $p->pre_immutable_hook;
+
     method $name => sub {
         my ($app, $name, $config, $methods) = @_;
 
@@ -32,7 +34,11 @@ role {
         $type =~ s/::.*$//;
 
         my $meta = Moose->init_meta( for_class => $name );
-        $meta->superclasses('Catalyst::' . $type);
+        my @superclasses = @{ $config->{superclasses} || [] };
+        push(@superclasses, 'Catalyst::' . $type) unless @superclasses;
+        $meta->superclasses(@superclasses);
+
+        Moose::Util::apply_all_roles( $meta, @{ $config->{roles}||[] } ) if @{ $config->{roles}||[] };
 
         if ($p->has_custom_component_method) {
             $meta->add_method(COMPONENT => $p->COMPONENT);
index 5435038..aeb3fe3 100644 (file)
@@ -41,7 +41,9 @@ sub _reflect_model_to_controller {
             $controller_methods{$method_name} = $app->generate_reflected_controller_action_method($suffix, $model_methods->{$method_name})
     }
 
-    $app->_setup_dynamic_controller( $controller_name, {}, \%controller_methods );
+    my $config_name = $controller_name;
+    $config_name =~ s/^[^:]+:://;
+    $app->_setup_dynamic_controller( $controller_name, $app->config->{$config_name}, \%controller_methods );
 }
 
 sub _setup_dynamic_controller_meta {
index 5049b43..48fed74 100644 (file)
@@ -19,8 +19,8 @@ our $VERSION = '0.01';
 __PACKAGE__->config(
     name => 'DynamicAppDemo',
     'Controller::One' => {
-        base_class => 'DynamicAppDemo::ControllerBase',
-        roles      => 'DynamicAppDemo::ControlleRole',
+        superclasses => [qw/DynamicAppDemo::ControllerBase/],
+        roles      => [qw/DynamicAppDemo::ControllerRole/],
     },
     'Model::One' => {
         class => 'SomeModelClass',