[Catalyst-commits] r9768 - in Catalyst-Runtime/5.80/trunk: . lib t

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Apr 21 00:27:57 GMT 2009


Author: t0m
Date: 2009-04-21 01:27:57 +0100 (Tue, 21 Apr 2009)
New Revision: 9768

Added:
   Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose_controller.t
Modified:
   Catalyst-Runtime/5.80/trunk/Changes
   Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Log:
Fixed non-moose classes initialization order issues. Not quite as fugly as I first thought, but still kills kittens

Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes	2009-04-20 23:03:25 UTC (rev 9767)
+++ Catalyst-Runtime/5.80/trunk/Changes	2009-04-21 00:27:57 UTC (rev 9768)
@@ -1,5 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Work around issues in Moose with initialization order of multiple
+          levels of non-Moose classes inheriting from a Moose class (t0m)
+          - Test for this
         - Add backwards compatibility method for Catalyst::Log->body, which
           has been made private (t0m)
         - Fix so that calling $c->req->parameters(undef) does not flatten

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2009-04-20 23:03:25 UTC (rev 9767)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2009-04-21 00:27:57 UTC (rev 9768)
@@ -2,6 +2,7 @@
 
 use Moose;
 extends 'Catalyst::Component';
+use Moose::Util qw/find_meta/;
 use bytes;
 use Scope::Upper ();
 use Catalyst::Exception;
@@ -2161,6 +2162,14 @@
 
 =cut
 
+sub _controller_init_base_classes {
+    my ($class, $component) = @_;
+    foreach my $class ( reverse @{ mro::get_linear_isa($component) } ) {
+        Moose->init_meta( for_class => $class )
+            unless find_meta($class);
+    }
+}
+
 sub setup_component {
     my( $class, $component ) = @_;
 
@@ -2168,6 +2177,14 @@
         return $component;
     }
 
+    # FIXME - Ugly, ugly hack to ensure the we force initialize non-moose base classes
+    #         nearest to Catalyst::Controller first, no matter what order stuff happens
+    #         to be loaded. There are TODO tests in Moose for this, see
+    #         f2391d17574eff81d911b97be15ea51080500003
+    if ($component->isa('Catalyst::Controller')) {
+        $class->_controller_init_base_classes($component);
+    }
+    
     my $suffix = Catalyst::Utils::class2classsuffix( $component );
     my $config = $class->config->{ $suffix } || {};
 

Added: Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose_controller.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose_controller.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose_controller.t	2009-04-21 00:27:57 UTC (rev 9768)
@@ -0,0 +1,26 @@
+use Catalyst ();
+
+{
+    package TestApp::Controller::Base;
+    use base qw/Catalyst::Controller/;
+}
+{
+    package TestApp::Controller::Other;
+    use base qw/TestApp::Controller::Base/;
+}
+
+Catalyst->setup_component('TestApp::Controller::Other');
+Catalyst->setup_component('TestApp::Controller::Base');
+
+use Test::More tests => 1;
+use Test::Exception;
+
+# Metaclass init order causes fail.
+# There are TODO tests in Moose for this, see
+# f2391d17574eff81d911b97be15ea51080500003
+# after which the evil kludge in core can die in a fire.
+
+lives_ok {
+    TestApp::Controller::Base->get_action_methods
+} 'Base class->get_action_methods ok when sub class initialized first';
+




More information about the Catalyst-commits mailing list