Reverting back to old behavior for components
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index 0c0b8cc..f74fa73 100644 (file)
@@ -627,11 +627,7 @@ sub retrieve_components {
         die qq/Couldn't load components "$error"/;
     }
 
-    $self->components( {} );
-
-    for my $component ( $self->_components ) {
-        $self->components->{$component} = $component;
-    }
+    return $self->_components;
 }
 
 =item $c->run
@@ -668,7 +664,6 @@ Setup.
 
 sub setup {
     my $self = shift;
-    $self->retrieve_components;
     $self->setup_components;
     if ( $self->debug ) {
         my $name = $self->config->{name} || 'Application';
@@ -685,26 +680,30 @@ Setup components.
 sub setup_components {
     my $self = shift;
 
-    my @components;
-    for my $component ( keys %{ $self->components } ) {
-
-        unless ( UNIVERSAL::isa( $component, 'Catalyst::Base' ) ) {
-            next;
-        }
-
-        my $instance;
-
-        eval { $instance = $component->new($self) };
-
-        if ( $@ ) {
-            die( qq/Couldn't instantiate "$component", "$@"/ );
-        }
+    # Components
+    my $class = ref $self || $self;
+    eval <<"";
+        package $class;
+        import Module::Pluggable::Fast
+          name   => '_components',
+          search => [
+            '$class\::Controller', '$class\::C',
+            '$class\::Model',      '$class\::M',
+            '$class\::View',       '$class\::V'
+          ];
 
-        $self->components->{$component} = $instance;
+    if ( my $error = $@ ) {
+        chomp $error;
+        die qq/Couldn't load components "$error"/;
+    }
 
-        push @components, $component;
+    $self->components( {} );
+    my @comps;
+    for my $comp ( $self->_components($self) ) {
+        $self->components->{ ref $comp } = $comp;
+        push @comps, $comp;
     }
-    
+
     my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
     $t->setCols('Class');
     $t->setColWidth( 'Class', 75, 1 );
@@ -712,7 +711,7 @@ sub setup_components {
     $self->log->debug( 'Loaded components', $t->draw )
       if ( @{ $t->{tbl_rows} } && $self->debug );
 
-    $self->setup_actions( [ $self, @components ] );
+    $self->setup_actions( [ $self, @comps ] );
 }
 
 =item $c->state