}
# $self->_command2action( $c, $command [, \@arguments ] )
-# Search for an action, from the command and returns C<($action, $args)> on
+# $self->_command2action( $c, $command [, \@captures, \@arguments ] )
+# Search for an action, from the command and returns C<($action, $args, $captures)> on
# success. Returns C<(0)> on error.
sub _command2action {
return 0;
}
- my @args;
+ my (@args, @captures);
+
+ if ( ref( $extra_params[-2] ) eq 'ARRAY' ) {
+ @captures = @{ pop @extra_params };
+ }
if ( ref( $extra_params[-1] ) eq 'ARRAY' ) {
@args = @{ pop @extra_params }
$action = $self->_invoke_as_component( $c, $command, $method );
}
- return $action, \@args;
+ return $action, \@args, \@captures;
}
=head2 $self->visit( $c, $command [, \@arguments ] )
my $self = shift;
my $opname = shift;
my ( $c, $command ) = @_;
- my ( $action, $args ) = $self->_command2action(@_);
+ my ( $action, $args, $captures ) = $self->_command2action(@_);
my $error = qq/Couldn't $opname("$command"): /;
if (!$action) {
$action = $self->expand_action($action);
local $c->request->{arguments} = $args;
+ local $c->request->{captures} = $captures;
local $c->{namespace} = $action->{'namespace'};
local $c->{action} = $action;
my $self = shift;
my $opname = shift;
my ( $c, $command ) = @_;
- my ( $action, $args ) = $self->_command2action(@_);
+ my ( $action, $args, $captures ) = $self->_command2action(@_);
if (!$action) {
my $error .= qq/Couldn't $opname to command "$command": /
);
ok( !$response->is_success, 'Response Fails' );
is( $response->content,
- q[FATAL ERROR: Couldn't visit("TestApp"): Action has no namespace: cannot visit() to a plain method or component, must be a :Action or some sort.],
+ q{FATAL ERROR: Couldn't visit("TestApp"): Action has no namespace: cannot visit() to a plain method or component, must be a :Action or some sort.},
"Cannot visit app namespace"
);
}
my $expected = join( ", ", @expected );
for my $i ( 1..3 ) {
- ok( my $response = request("http://localhost/action/visit/visit_chained/$i"),
+ ok( my $response = request("http://localhost/action/visit/visit_chained/$i/becomescapture/arg1/arg2"),
"visit to chained + subcontroller endpoint for $i" );
is( $response->header('X-Catalyst-Executed'),
$expected, "Executed actions for $i" );
- is( $response->content, "; $i", "Content OK for $i" );
+ is( $response->content, "arg1, arg2; becomescapture",
+ "Content OK for $i" );
}
}
}
sub visit_chained : Local {
- my ( $self, $c, $val ) = @_;
- $val eq 1 ? $c->visit( '/action/chained/foo/spoon', [$val] )
- : $val eq 2 ? $c->visit( qw/ Action::Chained::Foo spoon /, [$val] )
- : $c->visit( $c->controller('Action::Chained::Foo')->action_for('spoon'), [$val] )
+ my ( $self, $c, $val, $capture, @args ) = @_;
+ my @cap_and_args = ([$capture], [@args]);
+ $val eq 1 ? $c->visit( '/action/chained/foo/spoon', @cap_and_args)
+ : $val eq 2 ? $c->visit( qw/ Action::Chained::Foo spoon /, @cap_and_args)
+ : $c->visit( $c->controller('Action::Chained::Foo')->action_for('spoon'), @cap_and_args)
}
sub view : Local {