Fix tests, add autobox to flatten interface roles so you can use a string or array...
t0m [Sun, 7 Jun 2009 01:58:56 +0000 (02:58 +0100)]
Makefile.PL
lib/CatalystX/DynamicComponent/ModelToControllerReflector.pm
t/04_dynamicmodel.t
t/08_types_in_model.t [deleted file]
t/lib/DynamicAppDemo.pm
t/lib/SomeModelClass.pm

index 0b3e661..13b2da4 100644 (file)
@@ -10,11 +10,9 @@ requires 'namespace::autoclean';
 requires 'MooseX::Types' => '0.10';
 requires 'MooseX::Role::Parameterized' => '0.06';
 requires 'Catalyst::Runtime' => '5.80004';
+requires 'Moose::Autobox' => undef; # ->flatten
 requires 'List::MoreUtils';
 
-requires 'MooseX::Types::Structured';
-requires 'MooseX::Lexical::Types';
-
 resources repository => 'git@github.com:bobtfish/catalyst-dynamicappdemo.git';
 
 auto_install;
index c61437a..a3a5804 100644 (file)
@@ -2,6 +2,7 @@ package CatalystX::DynamicComponent::ModelToControllerReflector;
 use Moose::Role;
 use Moose::Util qw/does_role/;
 use List::MoreUtils qw/uniq/;
+use Moose::Autobox;
 use namespace::autoclean;
 
 my $mangle_attributes_on_generated_methods = sub {
@@ -47,8 +48,9 @@ sub _reflect_model_to_controller {
     my %controller_methods;
     # FIXME - Abstract this strategy crap out.
     my $model_methods = $model->meta->get_method_map;
-    my $interface_roles = $app->config->{$model_name}->{interface_roles};
-
+    my $interface_roles = [ uniq(($app->config->{$model_name}->{interface_roles}||=[])->flatten,
+        ($app->config->{'CatalystX::DynamicComponent::ModelToControllerReflector'}->{interface_roles}||=[])->flatten) ];
+    
     for my $interface_role (@$interface_roles) {
             for my $required_method ($interface_role->meta->get_required_method_list) {
                     # Note need to pass model name, as the method actually comes from
index 48274a5..00b8e90 100644 (file)
@@ -12,7 +12,7 @@ my $model = DynamicAppDemo->model('One');
 
 ok $model;
 isa_ok $model, 'SomeModelClass';
-is $model->say_hello('world'), 'Hello world';
+is_deeply $model->say_hello({name => 'world'}), { type => 'say_hello_response', body => 'Hello world' };
 
 ok(DynamicAppDemo->model('Two'), 'Have model Two');
 
diff --git a/t/08_types_in_model.t b/t/08_types_in_model.t
deleted file mode 100644 (file)
index 1b3aadb..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-use strict;
-use warnings;
-
-use FindBin qw/$Bin/;
-use lib "$Bin/lib";
-
-use Test::More tests => 6;
-use Test::Exception;
-
-use SomeModelClass;
-my $i = SomeModelClass->new;
-
-throws_ok { $i->say_hello(); } qr/Validation failed/;
-throws_ok { $i->say_hello({}); } qr/Validation failed/;
-throws_ok { $i->say_hello({name => 'Fred'}); } qr/Validation failed/;
-my $r;
-lives_ok { $r = $i->say_hello({type => 'say_hello', name => 'Fred'}); };
-ok $r;
-is_deeply($r, { type => 'say_hello_response', body => "Hello Fred" });
-
index 7b8e288..f5e0397 100644 (file)
@@ -17,6 +17,9 @@ __PACKAGE__->config(
         superclasses => [qw/DynamicAppDemo::ControllerBase/],
         roles      => [qw/DynamicAppDemo::ControllerRole/],
     },
+    'CatalystX::DynamicComponent::ModelToControllerReflector' => {
+        interface_roles => 'SomeModelClassInterface',
+    },
     'CatalystX::DynamicComponent::ModelsFromConfig' => {
         include => 'One|Two|Four',
         exclude => 'Four',
index 83f7271..1b1d539 100644 (file)
@@ -21,6 +21,7 @@ use namespace::autoclean;
 command say_hello => sub {
     my ($self, $document) = @_;
 
+    confess("Not a hash") unless (ref($document) eq 'HASH');
     my $name = $document->{name};
     return({ type => 'say_hello_response',