init_arg => undef,
);
+has action_args => (is => 'ro');
+
# ->config(actions => { '*' => ...
has _all_actions_attributes => (
is => 'ro',
my %args = @_;
my $class = $self->action_class(%args);
- my $action_args = $self->config->{action_args};
+ my $action_args = (
+ ref($self)
+ ? $self->action_args
+ : $self->config->{action_args}
+ );
my %extra_args = (
%{ $action_args->{'*'} || {} },
is_deeply $action->attributes->{extra_attribute}, [13];
is_deeply $action->attributes->{another_extra_attribute}, ['foo'];
}
+ {
+ ok( my $response = request('http://localhost/action_action_nine'),
+ 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->content_type, 'text/plain', 'Response Content-Type' );
+ is( $response->header('X-Catalyst-Action'),
+ 'action_action_nine', 'Test Action' );
+ is(
+ $response->header('X-Test-Class'),
+ 'TestApp::Controller::Action::Action',
+ 'Test Class'
+ );
+ is( $response->header('X-TestExtraArgsAction'), '42,13', 'Extra args get passed to action constructor' );
+ like(
+ $response->content,
+ qr/^bless\( .* 'Catalyst::Request' \)$/s,
+ 'Content is a serialized Catalyst::Request'
+ );
+ }
}
done_testing;
package TestApp;
-
use strict;
use Catalyst qw/
Test::MangleDollarUnderScore
our $VERSION = '0.01';
-TestApp->config( name => 'TestApp', root => '/some/dir', use_request_uri_for_path => 1 );
+TestApp->config(
+ name => 'TestApp',
+ root => '/some/dir',
+ use_request_uri_for_path => 1,
+ 'Controller::Action::Action' => {
+ action_args => {
+ action_action_nine => { another_extra_arg => 13 }
+ }
+ }
+);
# Test bug found when re-adjusting the metaclass compat code in Moose
# in 292360. Test added to Moose in 4b760d6, but leave this attribute
--- /dev/null
+package TestApp::Action::TestActionArgsFromConstructor;
+
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::Action';
+
+has [qw/extra_arg another_extra_arg/] => ( is => 'ro' );
+
+after execute => sub {
+ my ($self, $controller, $ctx) = @_;
+ $ctx->response->header('X-TestExtraArgsAction' => join q{,} => $self->extra_arg, $self->another_extra_arg);
+};
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
$c->forward('TestApp::View::Dump::Action');
}
+sub action_action_nine : Global : ActionClass('~TestActionArgsFromConstructor') {
+ my ( $self, $c ) = @_;
+ $c->forward('TestApp::View::Dump::Request');
+}
1;