get_all_components is getting until we know what to do
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 65bc1dc..c87bff2 100644 (file)
@@ -564,13 +564,7 @@ If you want to search for controllers, pass in a regexp as the argument.
 
 =cut
 
-sub controller {
-    my ( $c, $name, @args ) = @_;
-
-    $name ||= Catalyst::Utils::class2classshortsuffix( $c->action->class );
-
-    return $c->container->get_component_from_sub_container( 'controller', $name, $c, @args);
-}
+sub controller { shift->_lookup_mvc('controller', @_) }
 
 =head2 $c->model($name)
 
@@ -593,20 +587,7 @@ If you want to search for models, pass in a regexp as the argument.
 
 =cut
 
-sub model {
-    my ( $c, $name, @args ) = @_;
-
-    if (ref $c && !$name) {
-        my $current_instance = $c->stash->{current_model_instance};
-        return $current_instance
-            if $current_instance;
-
-        $name = $c->stash->{current_model};
-    }
-
-    return $c->container->get_component_from_sub_container( 'model', $name, $c, @args);
-}
-
+sub model { shift->_lookup_mvc('model', @_) }
 
 =head2 $c->view($name)
 
@@ -629,18 +610,23 @@ If you want to search for views, pass in a regexp as the argument.
 
 =cut
 
-sub view {
-    my ( $c, $name, @args ) = @_;
+sub view { shift->_lookup_mvc('view', @_) }
+
+sub _lookup_mvc {
+    my ( $c, $type, $name, @args ) = @_;
 
     if (ref $c && !$name) {
-        my $current_instance = $c->stash->{current_view_instance};
+        my $current_instance = $c->stash->{"current_${type}_instance"};
         return $current_instance
-            if $current_instance;
+            if $current_instance && $type ne 'controller';
 
-        $name = $c->stash->{current_view};
+        $name = $type eq 'controller'
+              ? Catalyst::Utils::class2classshortsuffix($c->action->class)
+              : $c->stash->{"current_${type}"}
+              ;
     }
 
-    return $c->container->get_component_from_sub_container( 'view', $name, $c, @args);
+    return $c->container->get_component_from_sub_container($type, $name, $c, @args);
 }
 
 =head2 $c->controllers
@@ -1031,11 +1017,11 @@ EOF
 
     if (
         $class->debug and
-        my @comps_names_types = $class->container->get_components_names_types
+        my $comps = $class->container->get_all_components($class)
     ) {
         my $column_width = Catalyst::Utils::term_width() - 8 - 9;
         my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 8, 'Type' ] );
-        $t->row( @$_ ) for @comps_names_types;
+        $t->row( $_ => ref($comps->{$_}) ? 'instance' : 'class' ) for keys %$comps;
 
         $class->log->debug( "Loaded components:\n" . $t->draw . "\n" );
     }
@@ -1449,7 +1435,7 @@ sub components {
         $container->add_component( $_ ) for keys %$comps;
     }
 
-    return $container->get_all_components();
+    return $container->get_all_components($class);
 }
 
 =head2 $c->context_class
@@ -2281,14 +2267,14 @@ sub setup_actions { my $c = shift; $c->dispatcher->setup_actions( $c, @_ ) }
 sub setup_config {
     my $class = shift;
 
-    my $args = $class->config || {};
-
-    my @container_classes = ( "${class}::Container", 'Catalyst::IOC::Container');
-    unshift @container_classes, delete $args->{container_class} if exists $args->{container_class};
+    my %args = %{ $class->config || {} };
 
-    my $container_class = Class::MOP::load_first_existing_class(@container_classes);
+    my $container_class = exists $args{container_class}
+                        ? Class::MOP::load_class(delete $args{container_class})
+                        : Class::MOP::load_first_existing_class("${class}::Container", 'Catalyst::IOC::Container')
+                        ;
 
-    my $container = $container_class->new( application_name => "$class", name => "$class" );
+    my $container = $container_class->new( %args, application_name => "$class", name => "$class" );
     $class->container($container);
 
     my $config = $container->resolve( service => 'config' );
@@ -2314,9 +2300,7 @@ The C<setup_components> config option is passed to both of the above methods.
 
 =cut
 
-sub setup_components {
-    shift->container->setup_components();
-}
+sub setup_components { shift->container->setup_components }
 
 =head2 locate_components