moving _find_component to the container as find_component
André Walker [Thu, 21 Jul 2011 00:08:41 +0000 (21:08 -0300)]
lib/Catalyst.pm
lib/Catalyst/IOC/Container.pm

index b59a1b0..ef446fb 100644 (file)
@@ -680,28 +680,6 @@ sub views {
     return $c->container->get_sub_container('view')->get_service_list;
 }
 
-sub _find_component {
-    my ($c, $component, @args) = @_;
-    my @result;
-
-    my $query = ref $component
-              ? $component
-              : qr{^$component$}
-              ;
-
-    for my $subcontainer_name (qw/model view controller/) {
-        my $subcontainer = $c->container->get_sub_container($subcontainer_name);
-        my @components   = $subcontainer->get_service_list;
-        @result          = grep { m{$component} } @components;
-
-        return map { $subcontainer->get_component( $_, $c, @args ) } @result
-            if @result;
-    }
-
-    # it expects an empty list on failed searches
-    return @result;
-}
-
 =head2 $c->comp($name)
 
 =head2 $c->component($name)
@@ -721,7 +699,7 @@ sub component {
 
     unless ($component) {
         $c->log->warn('Calling $c->component with no args is deprecated and ');
-        $c->log->warn('will be removed in future releases.');
+        $c->log->warn('will be removed in a future release.');
         $c->log->warn('Use $c->component_list instead.');
         return $c->component_list;
     }
@@ -732,7 +710,7 @@ sub component {
         $type, $name, $c, @args
     ) if $type;
 
-    my @result = $c->_find_component( $component, @args );
+    my @result = $c->container->find_component( $component, $c, @args );
 
     # list context for regexp searches
     return @result if ref $component;
@@ -750,7 +728,8 @@ sub component {
     # I would expect to return an empty list here, but that breaks back-compat
     $c->log->warn('Component not found, returning the list of existing');
     $c->log->warn('components. This behavior is deprecated and will be');
-    $c->log->warn('removed in future releases. Use $c->component_list instead.');
+    $c->log->warn('removed in a future release. Use $c->component_list');
+    $c->log->warn('instead.');
 
     return $c->component_list;
 }
index 886d597..b2766ab 100644 (file)
@@ -430,6 +430,29 @@ sub get_component_from_sub_container {
     return;
 }
 
+sub find_component {
+    my ( $self, $component, @args ) = @_;
+    my @result;
+
+    my $query = ref $component
+              ? $component
+              : qr{^$component$}
+              ;
+
+    for my $subcontainer_name (qw/model view controller/) {
+        my $subcontainer = $self->get_sub_container($subcontainer_name);
+        my @components   = $subcontainer->get_service_list;
+        @result          = grep { m{$component} } @components;
+
+        return map { $subcontainer->get_component( $_, @args ) } @result
+            if @result;
+    }
+
+    # it expects an empty list on failed searches
+    return @result;
+}
+
+
 1;
 
 __END__
@@ -480,6 +503,8 @@ Catalyst::Container - IOC for Catalyst components
 
 =head2 get_component_from_sub_container
 
+=head2 find_component
+
 =head2 _fix_syntax
 
 =head2 _config_substitutions