fixed what i've borked
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index 5b3e3d5..510ca4d 100644 (file)
@@ -121,13 +121,13 @@ sub dispatch {
         $c->state(1);
         if ( my $begin = @{ $c->get_action( 'begin', $namespace ) }[-1] ) {
             $c->execute( @{ $begin->[0] } );
-            return if scalar @{$c->error};
-            last unless $c->state;
+            return if scalar @{ $c->error };
         }
 
         # Execute the auto chain
         for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) {
             $c->execute( @{ $auto->[0] } );
+            return if scalar @{ $c->error };
             last unless $c->state;
         }
 
@@ -141,8 +141,7 @@ sub dispatch {
         # Execute last end
         if ( my $end = @{ $c->get_action( 'end', $namespace ) }[-1] ) {
             $c->execute( @{ $end->[0] } );
-            return if scalar @{$c->error};
-            last unless $c->state;            
+            return if scalar @{ $c->error };
         }
     }
     else {
@@ -204,8 +203,12 @@ sub execute {
         else { $c->state( &$code( $class, $c, @{ $c->req->args } ) ) }
     };
     if ( my $error = $@ ) {
-        chomp $error;
-        $error = qq/Caught exception "$error"/;
+
+        unless ( ref $error ) {
+            chomp $error;
+            $error = qq/Caught exception "$error"/;
+        }
+
         $c->log->error($error);
         $c->error($error);
         $c->state(0);
@@ -437,6 +440,8 @@ sub forward {
     }
     for my $result ( @{$results} ) {
         $c->execute( @{ $result->[0] } );
+        return if scalar @{ $c->error };
+        last unless $c->state;
     }
     return $c->state;
 }
@@ -791,7 +796,7 @@ sub set_action {
             $absolute = 1;
         }
         $absolute = 1 if $flags{global};
-        my $name = $absolute ? $path : "$prefix/$path";
+        my $name = $absolute ? $path : $prefix ? "$prefix/$path" : $path;
         $c->actions->{plain}->{$name} = [ $namespace, $code ];
     }
     if ( my $regex = $flags{regex} ) {