[Catalyst-commits] r10502 - in Catalyst-Runtime/5.80/trunk: lib t
t/aggregate t/lib/TestAppOneView/Controller
t/lib/TestAppOneView/View
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jun 11 12:42:01 GMT 2009
Author: caelum
Date: 2009-06-11 12:42:00 +0000 (Thu, 11 Jun 2009)
New Revision: 10502
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_view_single.t
Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/Controller/Root.pm
Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/View/Dummy.pm
Catalyst-Runtime/5.80/trunk/t/unit_core_mvc.t
Log:
fix $c->view() bug hopefully
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-06-11 07:27:56 UTC (rev 10501)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-06-11 12:42:00 UTC (rev 10502)
@@ -493,8 +493,13 @@
$c->error(0);
}
+sub _comp_search_prefixes {
+ my $c = shift;
+ return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_);
+}
+
# search components given a name and some prefixes
-sub _comp_search_prefixes {
+sub _comp_names_search_prefixes {
my ( $c, $name, @prefixes ) = @_;
my $appclass = ref $c || $c;
my $filter = "^${appclass}::(" . join( '|', @prefixes ) . ')::';
@@ -510,18 +515,18 @@
my $query = ref $name ? $name : qr/^$name$/i;
my @result = grep { $eligible{$_} =~ m{$query} } keys %eligible;
- return map { $c->components->{ $_ } } @result if @result;
+ return @result if @result;
# if we were given a regexp to search against, we're done.
return if ref $name;
# regexp fallback
$query = qr/$name/i;
- @result = map { $c->components->{ $_ } } grep { $eligible{ $_ } =~ m{$query} } keys %eligible;
+ @result = grep { $eligible{ $_ } =~ m{$query} } keys %eligible;
# no results? try against full names
if( !@result ) {
- @result = map { $c->components->{ $_ } } grep { m{$query} } keys %eligible;
+ @result = grep { m{$query} } keys %eligible;
}
# don't warn if we didn't find any results, it just might not exist
@@ -558,7 +563,9 @@
my $filter = "^${appclass}::(" . join( '|', @prefixes ) . ')::';
- my @names = map { s{$filter}{}; $_; } $c->_comp_search_prefixes( undef, @prefixes );
+ my @names = map { s{$filter}{}; $_; }
+ $c->_comp_names_search_prefixes( undef, @prefixes );
+
return @names;
}
Modified: Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_view_single.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_view_single.t 2009-06-11 07:27:56 UTC (rev 10501)
+++ Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_view_single.t 2009-06-11 12:42:00 UTC (rev 10502)
@@ -25,9 +25,11 @@
sub run_tests {
{
- is(get('/view_by_name?view=Dummy'), 'TestAppOneView::View::Dummy',
+ is(get('/view_by_name?view=Dummy'), 'AClass',
'$c->view("name") returns blessed instance');
- is(get('/view_no_args'), 'TestAppOneView::View::Dummy',
+ is(get('/view_by_regex?view=Dummy'), 'AClass',
+ '$c->view(qr/name/) returns blessed instance');
+ is(get('/view_no_args'), 'AClass',
'$c->view() returns blessed instance');
}
}
Modified: Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/Controller/Root.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/Controller/Root.pm 2009-06-11 07:27:56 UTC (rev 10501)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/Controller/Root.pm 2009-06-11 12:42:00 UTC (rev 10502)
@@ -21,4 +21,14 @@
$c->res->body(Scalar::Util::blessed($v));
}
+sub view_by_regex : Local {
+ my ( $self, $c ) = @_;
+
+ my $v_name = $c->req->param('view');
+
+ my ($v) = $c->view(qr/$v_name/);
+
+ $c->res->body(Scalar::Util::blessed($v));
+}
+
1;
Modified: Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/View/Dummy.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/View/Dummy.pm 2009-06-11 07:27:56 UTC (rev 10501)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestAppOneView/View/Dummy.pm 2009-06-11 12:42:00 UTC (rev 10502)
@@ -2,4 +2,12 @@
use base 'Catalyst::View';
+sub COMPONENT {
+ bless {}, 'AClass'
+}
+
+package AClass;
+
+use base 'Catalyst::View';
+
1;
Modified: Catalyst-Runtime/5.80/trunk/t/unit_core_mvc.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_core_mvc.t 2009-06-11 07:27:56 UTC (rev 10501)
+++ Catalyst-Runtime/5.80/trunk/t/unit_core_mvc.t 2009-06-11 12:42:00 UTC (rev 10502)
@@ -1,4 +1,4 @@
-use Test::More tests => 45;
+use Test::More tests => 46;
use strict;
use warnings;
@@ -8,9 +8,6 @@
map { "MyApp::$_"; }
qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/;
-my $thingie={};
-bless $thingie,'MyApp::Model::Test::Object';
-push @complist,$thingie;
{
package MyApp;
@@ -19,6 +16,10 @@
__PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } @complist } );
+ my $thingie={};
+ bless $thingie, 'Some::Test::Object';
+ __PACKAGE__->components->{'MyApp::Model::Test::Object'} = $thingie;
+
# allow $c->log->warn to work
__PACKAGE__->setup_log;
}
@@ -32,7 +33,7 @@
is( MyApp->model('Dummy::Model'), 'MyApp::Model::Dummy::Model', 'Model::Dummy::Model ok' );
-isa_ok( MyApp->model('Test::Object'), 'MyApp::Model::Test::Object', 'Test::Object ok' );
+isa_ok( MyApp->model('Test::Object'), 'Some::Test::Object', 'Test::Object ok' );
is( MyApp->controller('Model::Dummy::Model'), 'MyApp::Controller::Model::Dummy::Model', 'Controller::Model::Dummy::Model ok' );
@@ -81,7 +82,12 @@
no warnings 'redefine';
local *Catalyst::Log::warn = sub { $warnings++ };
- like (MyApp->model , qr/^MyApp\::(M|Model)\::/ , 'model() with no defaults returns *something*');
+ ok( my $model = MyApp->model );
+
+ ok( (($model =~ /^MyApp\::(M|Model)\::/) ||
+ $model->isa('Some::Test::Object')),
+ 'model() with no defaults returns *something*' );
+
ok( $warnings, 'model() w/o a default is random, warnings thrown' );
}
More information about the Catalyst-commits
mailing list