From: Tomas Doran Date: Sat, 21 Mar 2009 15:04:33 +0000 (+0000) Subject: Make CaptureArgs get passed, this makes the test less fail, but not perfect yet.... X-Git-Tag: 5.80001~57^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b456f8f32f13fc30b248264b05eda4aae66bf8c1 Make CaptureArgs get passed, this makes the test less fail, but not perfect yet. Also, needs docs.. --- diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 0f632e6..865dd2f 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -119,7 +119,8 @@ sub dispatch { } # $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 { @@ -130,7 +131,11 @@ 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 } @@ -158,7 +163,7 @@ sub _command2action { $action = $self->_invoke_as_component( $c, $command, $method ); } - return $action, \@args; + return $action, \@args, \@captures; } =head2 $self->visit( $c, $command [, \@arguments ] ) @@ -176,7 +181,7 @@ sub _do_visit { 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) { @@ -204,6 +209,7 @@ sub _do_visit { $action = $self->expand_action($action); local $c->request->{arguments} = $args; + local $c->request->{captures} = $captures; local $c->{namespace} = $action->{'namespace'}; local $c->{action} = $action; @@ -237,7 +243,7 @@ sub _do_forward { 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": / diff --git a/t/aggregate/live_component_controller_action_visit.t b/t/aggregate/live_component_controller_action_visit.t index f5a373d..febf935 100644 --- a/t/aggregate/live_component_controller_action_visit.t +++ b/t/aggregate/live_component_controller_action_visit.t @@ -253,7 +253,7 @@ sub run_tests { ); 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" ); } @@ -272,11 +272,12 @@ sub run_tests { 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" ); } } diff --git a/t/lib/TestApp/Controller/Action/Visit.pm b/t/lib/TestApp/Controller/Action/Visit.pm index 0447d34..9f8f9a5 100644 --- a/t/lib/TestApp/Controller/Action/Visit.pm +++ b/t/lib/TestApp/Controller/Action/Visit.pm @@ -61,10 +61,11 @@ sub visit_die : Local { } 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 {