[Catalyst-commits] r8513 - Catalyst-Runtime/5.80/trunk/lib/Catalyst

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Tue Oct 7 23:41:34 BST 2008


Author: rafl
Date: 2008-10-07 23:41:34 +0100 (Tue, 07 Oct 2008)
New Revision: 8513

Modified:
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
Log:
Improve error messages for forward/detach/visit/go. Patch by batman++

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm	2008-10-07 16:49:53 UTC (rev 8512)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm	2008-10-07 22:41:34 UTC (rev 8513)
@@ -84,18 +84,6 @@
 
     +My::Dispatch::Type
 
-=head2 $self->detach( $c, $command [, \@arguments ] )
-
-Documented in L<Catalyst>
-
-=cut
-
-sub detach {
-    my ( $self, $c, $command, @args ) = @_;
-    $c->forward( $command, @args ) if $command;
-    die $Catalyst::DETACH;
-}
-
 =head2 $self->dispatch($c)
 
 Delegate the dispatch to the action that matched the url, or return a
@@ -177,7 +165,8 @@
     my $error = qq/Couldn't $opname("$command"): /;
 
     if (!$action) {
-        $error .= qq/Invalid action or component./;
+        $error .= qq/Couldn't $opname to command "$command": /
+                 .qq/Invalid action or component./;
     }
     elsif (!defined $action->namespace) {
         $error .= qq/Action has no namespace: cannot $opname() to a plain /
@@ -226,30 +215,45 @@
 
 sub forward {
     my $self = shift;
+    $self->_do_forward(forward => @_);
+}
+
+sub _do_forward {
+    my $self = shift;
+    my $opname = shift;
     my ( $c, $command ) = @_;
     my ( $action, $args ) = $self->_command2action(@_);
 
-    unless ($action) {
-        my $error =
-            qq/Couldn't forward to command "$command": /
-          . qq/Invalid action or component./;
+    if (!$action) {
+        my $error .= qq/Couldn't $opname to command "$command": /
+                    .qq/Invalid action or component./;
         $c->error($error);
         $c->log->debug($error) if $c->debug;
         return 0;
     }
 
-    #push @$args, @_;
-
     no warnings 'recursion';
 
     my $orig_args = $c->request->arguments();
     $c->request->arguments($args);
     $action->dispatch( $c );
     $c->request->arguments($orig_args);
-    
+
     return $c->state;
 }
 
+=head2 $self->detach( $c, $command [, \@arguments ] )
+
+Documented in L<Catalyst>
+
+=cut
+
+sub detach {
+    my ( $self, $c, $command, @args ) = @_;
+    $self->_do_forward(detach => $c, $command, @args ) if $command;
+    die $Catalyst::DETACH;
+}
+
 sub _action_rel2abs {
     my ( $self, $c, $path ) = @_;
 




More information about the Catalyst-commits mailing list