support multiply attributes of the same name using the expected Catalyst style (arrayref)
John Napiorkowski [Fri, 13 Aug 2010 11:56:33 +0000 (07:56 -0400)]
lib/CatalystX/Declare/Keyword/Action.pm
t/100_complex.t
t/lib/TestApp/Controller/ActionParams.pm

index a348bbe..366f3ff 100644 (file)
@@ -234,9 +234,9 @@ class CatalystX::Declare::Keyword::Action {
             my ($role, $params) = @{$role_with_arg};
             if($params) {
                 my ($first, @rest) = eval $params;
-                my %params = ref $first eq 'HASH' ? %$first : ($first, @rest);
+                my %params = ref $first eq 'HASH' ? %$first : ($first, @rest); # both (%opts) and {%opts}
                 for my $key (keys %params) {
-                    $attrs->{$key} = [$params{$key}];
+                    push @{$attrs->{$key}}, $params{$key};
                 }
             }          
 
index 680353d..b3ae43c 100644 (file)
@@ -71,5 +71,6 @@ 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)';
 
 done_testing;
index aff3e0c..4b524a7 100644 (file)
@@ -5,10 +5,10 @@ role hasActionParams {
     has [qw/p1 p2/] => (is=>'ro', lazy_build=>1);
 
     method _build_p1 {
-        $self->attributes->{p1}->[0];
+        join ',', @{$self->attributes->{p1}};
     }
     method _build_p2 {
-        $self->attributes->{p2}->[0];
+        join ',', @{$self->attributes->{p2}};
     }
 }
 
@@ -43,5 +43,15 @@ controller ::Controller::ActionParams {
         my $p2 = $ctx->controller->action_for('third')->p2;
         $ctx->response->body("action_args_third: $p1,$p2");
     }
+
+    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;
+        $ctx->response->body("action_args_forth: $p1,$p2");
+    }
 }