5.30 2005-00-00 00:00:00
+ - Allow forward with arguments.
- Updated cookbook
- Allow overriding home/root in config.
- make module build cons README automatically.
}
}
-=item $c->forward($command)
+=item $c->forward($command [args]))
Forward processing to a private action or a method from a class.
If you define a class without method it will default to process().
+also takes an optional arrayref containing arguments to be passed
+to the new function. $c->req->args will be reset upon returning
+from the function.
$c->forward('/foo');
$c->forward('index');
my $caller = caller(0);
my $namespace = '/';
+ my $args;
+
+ if ( ref( $_[0] ) eq 'ARRAY' ) {
+ $args=$c->req->args();
+ $c->req->args( shift );
+ } elsif ( ref( $_[1] ) eq 'ARRAY' ) {
+ $args=$c->req->args();
+ $c->req->args( $_[1] );
+ }
if ( $command =~ /^\// ) {
$command =~ /^\/(.*)\/(\w+)$/;
for my $result ( @{$results} ) {
$c->execute( @{ $result->[0] } );
- return if scalar @{ $c->error };
+ last if scalar @{ $c->error };
last unless $c->state;
}
+ $c->req->args( $args ) if $args;
+ return if scalar @{ $c->error };
return $c->state;
}
use FindBin;
use lib "$FindBin::Bin/../../../lib";
-use Test::More tests => 18;
+use Test::More tests => 24;
use Catalyst::Test 'TestApp';
is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' );
like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' );
}
+
+{
+ ok( my $response = request('http://localhost/action/forward/with_args/old'), 'Request with args' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->content,'old');
+}
+
+{
+ ok( my $response = request('http://localhost/action/forward/with_method_and_args/old'), 'Request with args and method' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->content,'old');
+}
use strict;
use base 'TestApp::Controller::Action';
-sub one : Relative {
+sub one : Local {
my ( $self, $c ) = @_;
$c->forward('two');
}
$c->forward('three');
}
-sub three : Relative {
+sub three : Local {
my ( $self, $c ) = @_;
$c->forward('four');
}
$c->forward('/action/forward/five');
}
-sub five : Relative {
+sub five : Local {
my ( $self, $c ) = @_;
$c->forward('TestApp::View::Dump::Request');
}
-sub jojo : Relative {
+sub jojo : Local {
my ( $self, $c ) = @_;
$c->forward('one');
$c->forward('three');
}
-sub inheritance : Relative {
+sub inheritance : Local {
my ( $self, $c ) = @_;
$c->forward('/action/inheritance/a/b/default');
$c->forward('five');
}
-sub global : Relative {
+sub global : Local {
my ( $self, $c ) = @_;
- $c->forward('/global_action');
+ $c->forward( '/global_action' );
}
+sub with_args : Local {
+ my ( $self, $c, $orig ) = @_;
+ $c->forward( 'args',[qq/new/] );
+ $c->res->body( $c->req->args->[0] );
+}
+
+sub with_method_and_args : Local {
+ my ( $self, $c, $orig ) = @_;
+ $c->forward( qw/TestApp::Controller::Action::Forward args/, [qq/new/] );
+ $c->res->body( $c->req->args->[0] );
+}
+
+sub args : Local {
+ my ( $self, $c, $val ) = @_;
+ die "Expected argument 'new', got '$val'" unless $val eq 'new';
+ die "passed argument does not match args" unless $val eq $c->req->args->[0];
+}
1;