[Catalyst-commits] r7478 - in
Catalyst-Runtime/5.80/branches/context_go/lib: . Catalyst
batman at dev.catalyst.perl.org
batman at dev.catalyst.perl.org
Tue Mar 11 08:44:11 GMT 2008
Author: batman
Date: 2008-03-11 08:44:11 +0000 (Tue, 11 Mar 2008)
New Revision: 7478
Modified:
Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst/Dispatcher.pm
Log:
Added ->go() dispatcher handler: Missing tests and go() / forward() should be generalized
Modified: Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst/Dispatcher.pm 2008-03-11 05:25:42 UTC (rev 7477)
+++ Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst/Dispatcher.pm 2008-03-11 08:44:11 UTC (rev 7478)
@@ -127,6 +127,63 @@
}
}
+=head2 $self->go( $c, $command [, \@arguments ] )
+
+Documented in L<Catalyst>
+
+=cut
+
+sub go {
+ my ( $self, $c, $command, @extra_params ) = @_;
+
+ unless ($command) {
+ $c->log->debug('Nothing to go to') if $c->debug;
+ return 0;
+ }
+
+ my @args;
+
+ if ( ref( $extra_params[-1] ) eq 'ARRAY' ) {
+ @args = @{ pop @extra_params }
+ } else {
+ # this is a copy, it may take some abuse from ->_invoke_as_path if the path had trailing parts
+ @args = @{ $c->request->arguments };
+ }
+
+ my $action;
+
+ # go to a string path ("/foo/bar/gorch") or action object which stringifies to that
+ $action = $self->_invoke_as_path( $c, "$command", \@args );
+
+ # go to a component ( "MyApp::*::Foo" or $c->component("...") - a path or an object)
+ unless ($action) {
+ my $method = @extra_params ? $extra_params[0] : "process";
+ $action = $self->_invoke_as_component( $c, $command, $method );
+ }
+
+
+ unless ($action) {
+ my $error =
+ qq/Couldn't go to command "$command": /
+ . qq/Invalid action or component./;
+ $c->error($error);
+ $c->log->debug($error) if $c->debug;
+ return 0;
+ }
+
+ #push @$args, @_;
+
+ local $c->request->{arguments} = \@args;
+
+ $c->namespace($action->namespace);
+ $c->action($action);
+
+ $self->dispatch($c);
+
+ die $Catalyst::GO;
+}
+
+
=head2 $self->forward( $c, $command [, \@arguments ] )
Documented in L<Catalyst>
Modified: Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst.pm 2008-03-11 05:25:42 UTC (rev 7477)
+++ Catalyst-Runtime/5.80/branches/context_go/lib/Catalyst.pm 2008-03-11 08:44:11 UTC (rev 7478)
@@ -51,6 +51,7 @@
our $START = time;
our $RECURSION = 1000;
our $DETACH = "catalyst_detach\n";
+our $GO = "catalyst_go\n";
__PACKAGE__->mk_classdata($_)
for qw/components arguments dispatcher engine log dispatcher_class
@@ -329,6 +330,15 @@
sub detach { my $c = shift; $c->dispatcher->detach( $c, @_ ) }
+=head2 $c->go()
+
+Acts like an internal redirect, in you Catalyst app: Calls begin(), auto(),
+the new action and end() in the class you go() to.
+
+=cut
+
+sub go { my $c = shift; $c->dispatcher->go( $c, @_ ) }
+
=head2 $c->response
=head2 $c->res
@@ -1227,6 +1237,7 @@
if ( my $error = $@ ) {
if ( !ref($error) and $error eq $DETACH ) { die $DETACH if $c->depth > 1 }
+ elsif ( !ref($error) and $error eq $GO ) { die $GO if $c->depth > 1 }
else {
unless ( ref $error ) {
no warnings 'uninitialized';
More information about the Catalyst-commits
mailing list