moving block from ->component to container
André Walker [Sat, 23 Jul 2011 14:52:09 +0000 (11:52 -0300)]
lib/Catalyst.pm
lib/Catalyst/IOC/Container.pm

index 2e4f337..75459eb 100644 (file)
@@ -703,19 +703,8 @@ sub component {
         return $c->component_list;
     }
 
-    my ($type, $name) = _get_component_type_name($component);
-
-    return $c->container->get_component_from_sub_container(
-        $type, $name, $c, @args
-    ) if $type;
-
     my @result = $c->container->find_component( $component, $c, @args );
 
-    # one last search for things like $c->comp(qr/::M::/)
-    @result = $c->container->find_component_regexp(
-        $c->components, $component, $c, @args
-    ) if !@result and ref $component;
-
     # list context for regexp searches
     return @result if ref $component;
 
index 9b8243c..0672c83 100644 (file)
@@ -432,9 +432,14 @@ sub get_component_from_sub_container {
 }
 
 sub find_component {
-    my ( $self, $component, @args ) = @_;
+    my ( $self, $component, $c, @args ) = @_;
+    my ( $type, $name ) = Catalyst::_get_component_type_name($component);
     my @result;
 
+    return $self->get_component_from_sub_container(
+        $type, $name, $c, @args
+    ) if $type;
+
     my $query = ref $component
               ? $component
               : qr{^$component$}
@@ -445,10 +450,15 @@ sub find_component {
         my @components   = $subcontainer->get_service_list;
         @result          = grep { m{$component} } @components;
 
-        return map { $subcontainer->get_component( $_, @args ) } @result
+        return map { $subcontainer->get_component( $_, $c, @args ) } @result
             if @result;
     }
 
+    # one last search for things like $c->comp(qr/::M::/)
+    @result = $self->find_component_regexp(
+        $c->components, $component, $c, @args
+    ) if !@result and ref $component;
+
     # it expects an empty list on failed searches
     return @result;
 }