[Catalyst-commits] r8140 - in Catalyst-Runtime/5.70/trunk: . lib t

bricas at dev.catalyst.perl.org bricas at dev.catalyst.perl.org
Fri Jul 18 13:29:44 BST 2008


Author: bricas
Date: 2008-07-18 13:29:44 +0100 (Fri, 18 Jul 2008)
New Revision: 8140

Modified:
   Catalyst-Runtime/5.70/trunk/Changes
   Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm
   Catalyst-Runtime/5.70/trunk/t/unit_core_component.t
   Catalyst-Runtime/5.70/trunk/t/unit_core_mvc.t
Log:
Ensure ACCEPT_CONTEXT is called for results from component()

Modified: Catalyst-Runtime/5.70/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.70/trunk/Changes	2008-07-18 12:02:16 UTC (rev 8139)
+++ Catalyst-Runtime/5.70/trunk/Changes	2008-07-18 12:29:44 UTC (rev 8140)
@@ -4,6 +4,7 @@
         - Fix regressions for regexp fallback in model(), view() and controller()
         - Added the supplied argument to the regexp fallback warning for easier
           debugging
+        - Ensure ACCEPT_CONTEXT is called for results from component()
 
 5.7099_02 2008-07-16 19:10:00
         - Added PathPrefix attribute

Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm	2008-07-18 12:02:16 UTC (rev 8139)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm	2008-07-18 12:29:44 UTC (rev 8140)
@@ -683,11 +683,13 @@
 
         if( !ref $name ) {
             # is it the exact name?
-            return $comps->{ $name } if exists $comps->{ $name };
+            return $c->_filter_component( $comps->{ $name }, @args )
+                       if exists $comps->{ $name };
 
             # perhaps we just omitted "MyApp"?
             my $composed = ( ref $c || $c ) . "::${name}";
-            return $comps->{ $composed } if exists $comps->{ $composed };
+            return $c->_filter_component( $comps->{ $composed }, @args )
+                       if exists $comps->{ $composed };
 
             # search all of the models, views and controllers
             my( $comp ) = $c->_comp_search_prefixes( $name, qw/Model M Controller C View V/ );
@@ -698,12 +700,13 @@
         my $query = ref $name ? $name : qr{$name}i;
 
         my @result = grep { m{$query} } keys %{ $c->components };
-        return @result if ref $name;
+        return map { $c->_filter_component( $_, @args ) } @result if ref $name;
 
         if( $result[ 0 ] ) {
+            $c->log->warn( qq(Found results for "${name}" using regexp fallback.) );
             $c->log->warn( 'Relying on the regexp fallback behavior for component resolution' );
             $c->log->warn( 'is unreliable and unsafe. You have been warned' );
-            return $result[ 0 ];
+            return $c->_filter_component( $result[ 0 ], @args );
         }
 
         # I would expect to return an empty list here, but that breaks back-compat

Modified: Catalyst-Runtime/5.70/trunk/t/unit_core_component.t
===================================================================
--- Catalyst-Runtime/5.70/trunk/t/unit_core_component.t	2008-07-18 12:02:16 UTC (rev 8139)
+++ Catalyst-Runtime/5.70/trunk/t/unit_core_component.t	2008-07-18 12:29:44 UTC (rev 8140)
@@ -1,4 +1,4 @@
-use Test::More tests => 14;
+use Test::More tests => 22;
 use strict;
 use warnings;
 
@@ -23,16 +23,6 @@
 
 is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
 
-# regexp fallback
-{
-    my $warnings = 0;
-    no warnings 'redefine';
-    local *Catalyst::Log::warn = sub { $warnings++ };
-
-    is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok');
-    ok( $warnings, 'regexp fallback for comp() warns' );
-}
-
 is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok');
 
 # Is this desired behaviour?
@@ -44,6 +34,27 @@
     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');
+
+    # a couple other varieties for regexp fallback
+    is_deeply( [ MyApp->comp('M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok');
+
+    {
+        my $warnings = 0;
+        no warnings 'redefine';
+        local *Catalyst::Log::warn = sub { $warnings++ };
+
+        is_deeply( [ MyApp->comp('::M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok');
+        ok( $warnings, 'regexp fallback warnings' );
+
+        $warnings = 0;
+        is_deeply( [ MyApp->comp('Mode') ], [ 'MyApp::M::Model' ], 'Explicit return ok');
+        ok( $warnings, 'regexp fallback warnings' );
+
+        $warnings = 0;
+        is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok');
+        ok( $warnings, 'regexp fallback for comp() warns' );
+    }
+
 }
 
 # multiple returns
@@ -57,3 +68,21 @@
     is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' );
 }
 
+
+#checking @args passed to ACCEPT_CONTEXT
+{
+    my $args;
+
+    no warnings; 
+    *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args};
+
+    MyApp->component('MyApp::M::Model', qw/foo bar/);
+    is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok');
+
+    MyApp->component('M::Model', qw/foo2 bar2/);
+    is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok');
+
+    MyApp->component('Mode', qw/foo3 bar3/);
+    is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok');
+} 
+

Modified: Catalyst-Runtime/5.70/trunk/t/unit_core_mvc.t
===================================================================
--- Catalyst-Runtime/5.70/trunk/t/unit_core_mvc.t	2008-07-18 12:02:16 UTC (rev 8139)
+++ Catalyst-Runtime/5.70/trunk/t/unit_core_mvc.t	2008-07-18 12:29:44 UTC (rev 8140)
@@ -108,7 +108,7 @@
     is_deeply( [ MyApp->controller( qr{Dummy\::Model$} ) ], [ 'MyApp::Controller::Model::Dummy::Model' ], 'regexp controller ok' );
     is_deeply( [ MyApp->model( qr{Dum{2}y} ) ], [ 'MyApp::Model::Dummy::Model' ], 'regexp model ok' );
     
-    # ACCEPT_CONTEXT w/ qr{}
+    # object w/ qr{}
     is_deeply( [ MyApp->model( qr{Test} ) ], [ MyApp->components->{'MyApp::Model::Test::Object'} ], 'Object returned' );
 
     {
@@ -116,7 +116,7 @@
         no warnings 'redefine';
         local *Catalyst::Log::warn = sub { $warnings++ };
 
-        # ACCEPT_CONTEXT w/ regexp fallback
+        # object w/ regexp fallback
         is_deeply( [ MyApp->model( 'Test' ) ], [ MyApp->components->{'MyApp::Model::Test::Object'} ], 'Object returned' );
         ok( $warnings, 'regexp fallback warnings' );
     }




More information about the Catalyst-commits mailing list