Test case for a way to make C3 crap itself by partially using Moose + fix.
Tomas Doran [Tue, 30 Jun 2009 21:42:11 +0000 (21:42 +0000)]
Changes
lib/Catalyst.pm
t/c3_appclass_bug.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 930c7b2..ecdf7af 100644 (file)
--- a/Changes
+++ b/Changes
@@ -6,6 +6,8 @@
        - Inherited controller methods can now be specified in
          config->{action(s)}
        - Assigning an undef response body no longer produces warnings
+       - Fix C3 incompatibility bug caused if you use Moose in MyApp.pm and
+         add Catalyst to the right hand side of this in @ISA.
        - Make Catalyst.pm implement the Component::ApplicationAttribute
          interface so defining actions in MyApp.pm works again, if the
          actions have attributes that cause $self->_application to be used
index dcf566d..c938ab7 100644 (file)
@@ -103,12 +103,13 @@ sub import {
     }
 
     my $meta = Moose::Meta::Class->initialize($caller);
-    #Moose->import({ into => $caller }); #do we want to do this?
-
     unless ( $caller->isa('Catalyst') ) {
         my @superclasses = ($meta->superclasses, $class, 'Catalyst::Controller');
         $meta->superclasses(@superclasses);
     }
+    # Avoid possible C3 issues if 'Moose::Object' is already on RHS of MyApp
+    $meta->superclasses(grep { $_ ne 'Moose::Object' } $meta->superclasses);
+
     unless( $meta->has_method('meta') ){
         $meta->add_method(meta => sub { Moose::Meta::Class->initialize("${caller}") } );
     }
diff --git a/t/c3_appclass_bug.t b/t/c3_appclass_bug.t
new file mode 100644 (file)
index 0000000..0e5f7ed
--- /dev/null
@@ -0,0 +1,30 @@
+use strict;
+use Test::More tests => 1;
+
+{
+    package TestPlugin;
+    use strict;
+
+    sub setup {
+        shift->maybe::next::method(@_);
+    }
+}
+{
+    package TestAppC3ErrorUseMoose;
+    use Moose;
+
+    use Catalyst::Runtime 5.80;
+
+    use base qw/Catalyst/;
+    use Catalyst qw/
+        +TestPlugin
+    /;
+}
+
+use Test::Exception;
+lives_ok {
+    TestAppC3ErrorUseMoose->setup();
+} 'No C3 error';
+
+1;
+