From: John Napiorkowski Date: Fri, 13 Aug 2010 11:56:33 +0000 (-0400) Subject: support multiply attributes of the same name using the expected Catalyst style (arrayref) X-Git-Tag: 0.013~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-Declare.git;a=commitdiff_plain;h=34a0a1ffcd562d6f218cc766b0164e7eb286ef15 support multiply attributes of the same name using the expected Catalyst style (arrayref) --- diff --git a/lib/CatalystX/Declare/Keyword/Action.pm b/lib/CatalystX/Declare/Keyword/Action.pm index a348bbe..366f3ff 100644 --- a/lib/CatalystX/Declare/Keyword/Action.pm +++ b/lib/CatalystX/Declare/Keyword/Action.pm @@ -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}; } } diff --git a/t/100_complex.t b/t/100_complex.t index 680353d..b3ae43c 100644 --- a/t/100_complex.t +++ b/t/100_complex.t @@ -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; diff --git a/t/lib/TestApp/Controller/ActionParams.pm b/t/lib/TestApp/Controller/ActionParams.pm index aff3e0c..4b524a7 100644 --- a/t/lib/TestApp/Controller/ActionParams.pm +++ b/t/lib/TestApp/Controller/ActionParams.pm @@ -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"); + } }