From: André Walker Date: Thu, 21 Jul 2011 14:21:46 +0000 (-0300) Subject: making $c->comp(qr/::M::/) work X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e2b302e94a00616ee637bd2876591a014396e80;p=catagits%2FCatalyst-Runtime.git making $c->comp(qr/::M::/) work --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 92a888b..f71cac6 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -712,6 +712,11 @@ sub component { 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; diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index b2766ab..ffee749 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -452,6 +452,25 @@ sub find_component { return @result; } +sub find_component_regexp { + my ( $self, $components, $component, @args ) = @_; + my @result; + + my @components = grep { m{$component} } keys %{ $components }; + + for (@components) { + # FIXME this is naughty enough being called inside Catalyst.pm + # find some alternative for this sub and remember to delete here + my ($type, $name) = Catalyst::_get_component_type_name($_); + + push @result, $self->get_component_from_sub_container( + $type, $name, @args + ) if $type; + } + + return @result; +} + 1; @@ -505,6 +524,8 @@ Catalyst::Container - IOC for Catalyst components =head2 find_component +=head2 find_component_regexp + =head2 _fix_syntax =head2 _config_substitutions diff --git a/t/aggregate/unit_core_component.t b/t/aggregate/unit_core_component.t index 005015a..2875f0c 100644 --- a/t/aggregate/unit_core_component.t +++ b/t/aggregate/unit_core_component.t @@ -45,11 +45,6 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); # multiple returns { -# FIXME: this cannot be found by looking only in the container. -# either the test must be changed, or the regexp must be run against -# $c->components() in Catalyst.pm - diag('this test will not work by searching the container'); - diag('check the source of this file for more info'); my @expected = sort qw( MyApp::C::Controller MyApp::M::Model ); my @got = sort MyApp->comp( qr{::[MC]::} ); is_deeply( \@got, \@expected, 'multiple results from regexp ok' );