[Catalyst-commits] r11263 - in
Catalyst-Runtime/5.80/branches/component_registration-search_extra:
lib t/aggregate
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Fri Aug 28 00:55:23 GMT 2009
Author: t0m
Date: 2009-08-28 00:55:20 +0000 (Fri, 28 Aug 2009)
New Revision: 11263
Modified:
Catalyst-Runtime/5.80/branches/component_registration-search_extra/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/component_registration-search_extra/t/aggregate/live_component_registration-search_extra.t
Log:
Make search_extra actually work, by allowing ->model/component/controller/view and the list methods to find stuff in extra paths. This is all a massive bucket of suck - we should so work this out in advance so that you can just do a hash lookup or key list in those methods.
Modified: Catalyst-Runtime/5.80/branches/component_registration-search_extra/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/component_registration-search_extra/lib/Catalyst.pm 2009-08-27 23:05:03 UTC (rev 11262)
+++ Catalyst-Runtime/5.80/branches/component_registration-search_extra/lib/Catalyst.pm 2009-08-28 00:55:20 UTC (rev 11263)
@@ -510,17 +510,25 @@
return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_);
}
+sub _comp_names_appclass_filter {
+ my ( $c ) = @_;
+ my $appclass = ref $c || $c;
+ my @appclass_prefixes = ($appclass, @{ $c->config->{setup_components}{search_extra}||[] });
+ my $appclass_filter = "^(" . join('|', @appclass_prefixes) . ')';
+ return qr/$appclass_filter/;
+}
+
# search components given a name and some prefixes
sub _comp_names_search_prefixes {
my ( $c, $name, @prefixes ) = @_;
my $appclass = ref $c || $c;
- my $filter = "^${appclass}::(" . join( '|', @prefixes ) . ')::';
+ my $appclass_filter = $c->_comp_names_appclass_filter;
+ my $filter = $appclass_filter . '::(' . join( '|', @prefixes ) . ')::';
$filter = qr/$filter/; # Compile regex now rather than once per loop
# map the original component name to the sub part that we will search against
- my %eligible = map { my $n = $_; $n =~ s{^$appclass\::[^:]+::}{}; $_ => $n; }
+ my %eligible = map { my $n = $_; $n =~ s{^$appclass_filter\::[^:]+::}{}; $_ => $n }
grep { /$filter/ } keys %{ $c->components };
-
# undef for a name will return all
return keys %eligible if !defined $name;
@@ -573,7 +581,8 @@
my ( $c, @prefixes ) = @_;
my $appclass = ref $c || $c;
- my $filter = "^${appclass}::(" . join( '|', @prefixes ) . ')::';
+ my $appclass_filter = $c->_comp_names_appclass_filter;
+ my $filter = "^$appclass_filter\::(" . join( '|', @prefixes ) . ')::';
my @names = map { s{$filter}{}; $_; }
$c->_comp_names_search_prefixes( undef, @prefixes );
@@ -2149,7 +2158,7 @@
sub setup_components {
my $class = shift;
- my $config = $class->config->{ setup_components };
+ my $config = exists($class->config->{ setup_components }) ? $class->config->{ setup_components } : {};
my @comps = sort { length $a <=> length $b }
$class->locate_components($config);
@@ -2200,7 +2209,7 @@
my $config = shift;
my @paths = qw( ::Controller ::C ::Model ::M ::View ::V );
- my $extra = delete $config->{ search_extra } || [];
+ my $extra = exists($config->{ search_extra }) ? $config->{ search_extra } : [];
push @paths, @$extra;
Modified: Catalyst-Runtime/5.80/branches/component_registration-search_extra/t/aggregate/live_component_registration-search_extra.t
===================================================================
--- Catalyst-Runtime/5.80/branches/component_registration-search_extra/t/aggregate/live_component_registration-search_extra.t 2009-08-27 23:05:03 UTC (rev 11262)
+++ Catalyst-Runtime/5.80/branches/component_registration-search_extra/t/aggregate/live_component_registration-search_extra.t 2009-08-28 00:55:20 UTC (rev 11263)
@@ -12,9 +12,9 @@
use lib "$FindBin::Bin/../lib";
use Test::More;
+use Data::Dumper;
+plan tests => 9;
-plan tests => 8;
-
use_ok('TestAppSearchExtra');
# this is the regular behaviour for regular models, and always worked:
@@ -23,19 +23,16 @@
# now the "search_extra" components...
-ok( defined TestAppSearchExtra->component('FooBar'), 'The "search_extra" model FooBaz is a component ok - should work' );
+ok( defined TestAppSearchExtra->component('FooBar'), 'The "search_extra" model FooBar is found by ->component ok' );
+ok( defined TestAppSearchExtra->component('Baz'), 'The "search_extra" controller Baz is found by ->component ok' );
# this is the greatest regression and impacts the most:
-ok( defined TestAppSearchExtra->model('FooBar'), 'FooBar is a "search_extra" model - 5.71 regression' );
+ok( defined TestAppSearchExtra->model('FooBar'), 'FooBar is a model' );
+ok( defined TestAppSearchExtra->controller('Baz'), 'Baz is a controller' );
-# the following doesnt work either on 5.7x nor 5.8, but should...
+ok( grep( /Baz$/, TestAppSearchExtra->controllers ),
+ 'The "search_extra" Baz is in the controllers list' );
+ok( grep( /FooBar$/, TestAppSearchExtra->models ), 'FooBar is in the models list' );
-# on the model side:
-ok( grep( /^FooBar/, TestAppSearchExtra->models ), 'FooBar is in the models list - should work for consistency' );
-# on the controller side:
-ok( defined TestAppSearchExtra->component('Baz'),
- 'The "search_extra" controller Baz is a component - should work' );
-ok( grep( /^Baz/, TestAppSearchExtra->controllers ),
- 'The "search_extra" Baz is in the controllers list - should work for consistency' );
More information about the Catalyst-commits
mailing list