getting structure from Container
André Walker [Thu, 21 Jul 2011 19:22:32 +0000 (16:22 -0300)]
lib/Catalyst.pm
lib/Catalyst/IOC/Container.pm

index f71cac6..c9ccf8d 100644 (file)
@@ -1043,15 +1043,15 @@ EOF
 
     $class->setup_components;
 
-    if ( $class->debug ) { # XXX - Fixme to be a method on the container? (Or at least get a) data structure back from the container!!
+    if (
+        $class->debug and
+        my @comps_types = $class->container->get_components_types
+    ) {
         my $column_width = Catalyst::Utils::term_width() - 8 - 9;
         my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 8, 'Type' ] );
-        for my $comp ( sort keys %{ $class->components } ) {
-            my $type = ref $class->components->{$comp} ? 'instance' : 'class';
-            $t->row( $comp, $type );
-        }
-        $class->log->debug( "Loaded components:\n" . $t->draw . "\n" )
-          if ( keys %{ $class->components } );
+        $t->row( @$_ ) for @comps_types;
+
+        $class->log->debug( "Loaded components:\n" . $t->draw . "\n" );
     }
 
     $class->setup_actions;
index ffee749..11239e4 100644 (file)
@@ -471,6 +471,22 @@ sub find_component_regexp {
     return @result;
 }
 
+sub get_components_types {
+    my ( $self ) = @_;
+    my @comps_types;
+
+    for my $sub_container_name (qw/model view controller/) {
+        my $sub_container = $self->get_sub_container($sub_container_name);
+        for my $service ( $sub_container->get_service_list ) {
+            my $comp     = $self->resolve(service => $service);
+            my $compname = ref $comp || $comp;
+            my $type     = ref $comp ? 'instance' : 'class';
+            push @comps_types, [ $compname, $type ];
+        }
+    }
+
+    return @comps_types;
+}
 
 1;