Minor engine cleanup
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Dispatcher.pm
index 32ccd67..91e39a5 100644 (file)
@@ -65,16 +65,15 @@ sub dispatch {
         }
 
         # Execute the auto chain
-        my $auto = 0;
-        for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) {
+        my $auto;
+        for $auto ( @{ $c->get_action( 'auto', $namespace ) } ) {
             $c->execute( @{ $auto->[0] } );
             return if scalar @{ $c->error };
             last unless $c->state;
-            $auto++;
         }
 
         # Execute the action or last default
-        my $mkay = $auto ? $c->state ? 1 : 0 : 1;
+        my $mkay = defined $auto ? $c->state ? 1 : 0 : 1;
         if ( ( my $action = $c->req->action ) && $mkay ) {
             if ( my $result = @{ $c->get_action( $action, $default ) }[-1] ) {
                 $c->execute( @{ $result->[0] } );
@@ -135,11 +134,20 @@ sub forward {
 
     unless ( @{$results} ) {
         my $class = $command || '';
-        my $path  = $class . '.pm';
+        my $path = $class . '.pm';
         $path =~ s/::/\//g;
 
-        unless ( $INC{ $path } ) {
-            my $error = qq/Couldn't forward to "$class". Invalid or not loaded./;
+        unless ( $INC{$path} ) {
+            my $error =
+              qq/Couldn't forward to "$class". Invalid or not loaded./;
+            $c->error($error);
+            $c->log->debug($error) if $c->debug;
+            return 0;
+        }
+
+        unless ( UNIVERSAL::isa( $class, 'Catalyst::Base' ) ) {
+            my $error =
+              qq/Can't forward to "$class". Class is not a Catalyst component./;
             $c->error($error);
             $c->log->debug($error) if $c->debug;
             return 0;
@@ -153,7 +161,8 @@ sub forward {
         }
 
         else {
-            my $error = qq/Couldn't forward to "$class". Does not implement "$method"/;
+            my $error =
+              qq/Couldn't forward to "$class". Does not implement "$method"/;
             $c->error($error);
             $c->log->debug($error)
               if $c->debug;
@@ -347,7 +356,7 @@ sub setup_actions {
     for my $comp (@$comps) {
         $comp = ref $comp || $comp;
 
-        for my $action ( @{ $comp->_cache } ) {
+        for my $action ( @{ Catalyst::Utils::reflect_actions($comp) } ) {
             my ( $code, $attrs ) = @{$action};
             my $name = '';
             no strict 'refs';