fixed problem with deep trait parameters
John Napiorkowski [Tue, 5 Oct 2010 17:50:50 +0000 (13:50 -0400)]
Makefile.PL
lib/CatalystX/Declare.pm
lib/CatalystX/Declare/Controller/DetermineActionClass.pm
lib/CatalystX/Declare/Keyword/Action.pm
t/100_complex.t
t/lib/TestApp/Controller/ActionParams.pm

index c75a3ae..a74cae6 100644 (file)
@@ -19,6 +19,7 @@ BEGIN {
 name            'CatalystX-Declare';
 author          'Robert Sedlacek <rs@474.at>';
 license         'perl';
+version         '0.015';
 
 all_from        'lib/CatalystX/Declare.pm';
 readme_from     'lib/CatalystX/Declare.pm';
@@ -43,6 +44,7 @@ requires        'MooseX::Role::Parameterized',      '0.13';
 requires        'MooseX::Types',                    '0.20';
 requires        'MooseX::Method::Signatures',       '0.26';
 requires        'Catalyst::Controller::ActionRole', '0.15';
+requires        'Data::Pond',                       '0.002';
 requires        'FindBin';
 
 test_requires   'Test::More',                       '0.92';
index 057c6a2..0f91a5c 100644 (file)
@@ -11,7 +11,7 @@ class CatalystX::Declare extends MooseX::Declare is dirty {
 
     clean;
 
-    our $VERSION = '0.014';
+    our $VERSION = '0.015';
 
     around keywords (ClassName $self:) {
         $self->$orig,
index c608271..cbdb7d5 100644 (file)
@@ -6,7 +6,6 @@ role CatalystX::Declare::Controller::DetermineActionClass
     with CatalystX::Declare::Controller::QualifyClassNames {
 
     around create_action (%args) {
-
         my ($action_class) = @{ $args{attributes}{CatalystX_Declarative_ActionClass} || [] };
         $action_class ||= 'Catalyst::Action';
 
@@ -15,7 +14,6 @@ role CatalystX::Declare::Controller::DetermineActionClass
         Moose::Meta::Class->initialize($fq_class);
 
         $args{attributes}{ActionClass} ||= [$fq_class];
-
         return $self->$orig(%args);
     }
 }
index 17152cf..2e9bea8 100644 (file)
@@ -9,6 +9,7 @@ class CatalystX::Declare::Keyword::Action {
     use Data::Dump          qw( pp );
     use MooseX::Types::Util qw( has_available_type_export );
     use Moose::Util         qw( add_method_modifier ensure_all_roles );
+    use Data::Pond qw(pond_write_datum);
     use Class::Inspector;
     use Class::MOP;
 
@@ -143,10 +144,12 @@ class CatalystX::Declare::Keyword::Action {
                 next if $attr eq 'Chained' and $value eq UNDER_VAR;
 
                 push @attributes, 
-                    map { sprintf '%s%s', $attr, defined($_) ? sprintf('(%s)', $_) : '' }
-                        (ref($value) eq 'ARRAY') 
-                        ? @$value
-                        : $value;
+                    map {
+                        my $value = ref $_ ? pond_write_datum($_) : $_;
+                        sprintf '%s%s', $attr, defined($value) ? sprintf('(%s)', $value) : ''
+                    } (
+                        ref($value) eq 'ARRAY'
+                    ) ? @$value : $value;
             }
 
             return \@attributes;
@@ -184,7 +187,6 @@ class CatalystX::Declare::Keyword::Action {
             # merge runtime and compiletime attrs
             my %full_attrs = (%attributes, %$attrs);
             my $compiled_attrs = $compile_attrs->(\%full_attrs);
-
             my $real_method = $method->reify(
                 actual_body => $body,
                 attributes  => $compiled_attrs,
@@ -193,10 +195,8 @@ class CatalystX::Declare::Keyword::Action {
 
             # NYI
             if ($modifier) {
-
                 add_method_modifier $class, $modifier, [$name, $real_method];
-            }
-            else {
+            } else {
 
                 my $prepare_meta = sub {
                     my ($meta) = @_;
@@ -236,8 +236,10 @@ class CatalystX::Declare::Keyword::Action {
                 my ($first, @rest) = eval $params;
                 my %params = ref $first eq 'HASH' ? %$first : ($first, @rest); # both (%opts) and {%opts}
                 for my $key (keys %params) {
-                    my $parameters = ref $params{$key} eq 'ARRAY' ? @{$params{$key}} : $params{$key};
-                    push @{$attrs->{$key}}, $parameters;
+                    my $value = ref $params{$key} eq 'ARRAY' ? $params{$key} : [$params{$key}];
+                    push @{ $attrs->{$key} ||=[] }, @$value;
+                    ##push @{ $attrs->{$key} ||=[] }, $params;
+
                 }
             }          
 
@@ -248,7 +250,6 @@ class CatalystX::Declare::Keyword::Action {
         }
 
         push @{ $attrs->{CatalystX_Declarative_ActionRoles} ||= [] }, @roles;
-
         return;
     }
 
index 95be111..fdd5c6f 100644 (file)
@@ -71,9 +71,12 @@ is get('/foo/lower/down/the/param/3/road/5'), 8, 'capture args and block under w
 is get('/actionparams/first'), 'action_args_first: 100,101', 'actionrole with params';
 is get('/actionparams/second'), 'action_args_second: 200,201', 'actionrole with params (part two)';
 is get('/actionparams/third'), 'action_args_third: 300,301', 'actionrole with params (part three)';
-is get('/actionparams/forth'), 'action_args_forth: 400,1,401,2', 'actionrole with params (part four)';
 
+is get('/actionparams/forth'), 'action_args_forth: 400,1,401,2', 'actionrole with params (part four)';
 is get('/actionparams/first_app_ns'), 'action_args_first: 100,101', 'actionrole with params (from App NS)';
 is get('/actionparams/first_cat_ns'), 'action_args_first: 100,101', 'actionrole with params (from Cat NS)';
 
+# Check deep parsing
+is get('/actionparams/check_deep'), 'action_args_deep: {a=>1,b=>2}', 'actionrole with deep params';
+
 done_testing;
index 8208d04..5135111 100644 (file)
@@ -12,6 +12,13 @@ role hasActionParams {
     }
 }
 
+role hasActionParamsDeep {
+    has 'p_deep' => (is=>'ro', lazy_build=>1);
+    method _build_p_deep {
+        join ',', @{$self->attributes->{p_deep}};
+    }
+}
+
 controller ::Controller::ActionParams {
 
     action base
@@ -45,12 +52,13 @@ controller ::Controller::ActionParams {
     }
 
     action forth under base
-    with (hasActionParams(
-        p1=>400,
-        p2=>401,
-    ), hasActionParams(p1=>1,p2=>2)) is final {
-        my $p1 = $ctx->controller->action_for('forth')->p1;
-        my $p2 = $ctx->controller->action_for('forth')->p2;
+    with (
+        hasActionParams(p1=>400,p2=>401), 
+        hasActionParams(p1=>1,p2=>2, p0=>3)
+    ) is final {
+        my $action = $ctx->controller->action_for('forth');
+        my $p1 = $action->p1;
+        my $p2 = $action->p2;
         $ctx->response->body("action_args_forth: $p1,$p2");
     }
 
@@ -70,5 +78,14 @@ controller ::Controller::ActionParams {
         $ctx->response->body("action_args_first: $p1,$p2");
     }
 
+    action check_deep under base
+    with hasActionParamsDeep(p_deep=>{a=>1,b=>2}) is final {
+        my $action = $ctx->controller->action_for('check_deep');
+        my $p_deep = $action->p_deep;
+        ## $ctx->log->_dump($action->attributes);
+        $ctx->response->body("action_args_deep: $p_deep");
+    }
+
+
 }