more fixes to regexp fallback, ugh.
Brian Cassidy [Fri, 18 Jul 2008 01:21:07 +0000 (01:21 +0000)]
Changes
lib/Catalyst.pm
t/unit_core_component.t
t/unit_core_mvc.t

diff --git a/Changes b/Changes
index 03a5cb9..bf58e9a 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
 5.7xxxxxx XXXX
-        - Fix regression for regexp fallback in model(), view() and controller()
+        - Fix regressions for regexp fallback in model(), view() and controller()
 
 5.7099_02 2008-07-16 19:10:00
         - Added PathPrefix attribute
index c84253d..bed30ee 100644 (file)
@@ -454,6 +454,11 @@ sub _comp_search_prefixes {
     $query  = qr/$name/i;
     @result = map { $c->components->{ $_ } } grep { $eligible{ $_ } =~ m{$query} } keys %eligible;
 
+    # no results? try against full names
+    if( !@result ) {
+        @result = map { $c->components->{ $_ } } grep { m{$query} } keys %eligible;
+    }
+
     # don't warn if we didn't find any results, it just might not exist
     if( @result ) {
         $c->log->warn( 'Relying on the regexp fallback behavior for component resolution is unreliable and unsafe.' );
index 151763b..a4cb067 100644 (file)
@@ -1,4 +1,4 @@
-use Test::More tests => 11;
+use Test::More tests => 14;
 use strict;
 use warnings;
 
@@ -41,6 +41,9 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
 # regexp behavior
 {
     is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' );
+    is_deeply( [ MyApp->comp('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok');
+    is_deeply( [ MyApp->comp('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok');
+    is_deeply( [ MyApp->comp('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok');
 }
 
 # multiple returns
index 74b4ecf..9d35067 100644 (file)
@@ -1,4 +1,4 @@
-use Test::More tests => 40;
+use Test::More tests => 43;
 use strict;
 use warnings;
 
@@ -121,6 +121,9 @@ is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok');
         ok( $warnings, 'regexp fallback warnings' );
     }
 
+    is_deeply( [ MyApp->view('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok');
+    is_deeply( [ MyApp->controller('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok');
+    is_deeply( [ MyApp->model('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok');
 }
 
 {