C::P::A passes its tests against 5.80 now - fixed plugins having new methods by inlin...
Tomas Doran [Sun, 21 Dec 2008 19:48:59 +0000 (19:48 +0000)]
Changes
Makefile.PL
lib/Catalyst.pm
t/plugin_new_method_backcompat.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 1f8c841..c22ea2b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Make MyApp immutable at the end of the scope after the setup
+          method is called, fixing issues with plugins which have their 
+          own new methods by inlining a constructor on MyApp (t0m)
+          - Test for this and method modifiers in MyApp (t0m)
         - Fix Catalyst::Plugin::Authentication's authentication
           plugin backwards compatibility issues by fixing 
           Class::Data::Inheritable compatibility (t0m)
index e97a3ba..8f88af4 100644 (file)
@@ -6,6 +6,7 @@ name 'Catalyst-Runtime';
 all_from 'lib/Catalyst/Runtime.pm';
 
 requires 'namespace::clean';
+requires 'B::Hooks::EndOfScope';
 requires 'MooseX::Emulate::Class::Accessor::Fast' => '0.00600';
 requires 'Moose' => '0.59';
 requires 'Carp';
index 26b5b75..15b231b 100644 (file)
@@ -8,6 +8,7 @@ use Moose;
 use Class::MOP::Object ();
 extends 'Catalyst::Component';
 use bytes;
+use B::Hooks::EndOfScope;
 use Catalyst::Exception;
 use Catalyst::Log;
 use Catalyst::Request;
@@ -34,7 +35,6 @@ use Carp qw/croak carp/;
 
 BEGIN { require 5.008001; }
 
-# FIXME lazy => 1 here makes C::P::Auth tests pass?!?
 has stack => (is => 'ro', default => sub { [] });
 has stash => (is => 'rw', default => sub { {} });
 has state => (is => 'rw', default => 0);
@@ -1018,6 +1018,17 @@ EOF
     }
     $class->log->_flush() if $class->log->can('_flush');
 
+    # Make sure that the application class becomes immutable at this point, 
+    # which ensures that it gets an inlined constructor. This means that it 
+    # works even if the user has added a plugin which contains a new method.
+    # Note however that we have to do the work on scope end, so that method
+    # modifiers work correctly in MyApp (as you have to call setup _before_ 
+    # applying modifiers).
+    on_scope_end {
+        my $meta = $class->Moose::Object::meta();
+        $meta->make_immutable unless $meta->is_immutable;
+    };
+
     $class->setup_finished(1);
 }
 
diff --git a/t/plugin_new_method_backcompat.t b/t/plugin_new_method_backcompat.t
new file mode 100644 (file)
index 0000000..7aaef8b
--- /dev/null
@@ -0,0 +1,17 @@
+# Test that plugins with their own new method don't break applications.
+
+# 5.70 creates all of the request/response structure itself in prepare, 
+# and as the new method in our plugin just blesses our args, that works nicely.
+
+# In 5.80, we rely on the new method to appropriately initialise data 
+# structures, and therefore we need to inline a new method on MyApp to ensure
+# that plugins don't get it wrong for us.
+
+# Also tests method modifiers and etc in MyApp.pm still work as expected.
+
+use FindBin;
+use lib "$FindBin::Bin/lib";use Test::More tests => 3;
+
+use Catalyst::Test qw/TestAppPluginWithNewMethod/; # 1 test for adding a modifer not throwing.
+ok request('/foo')->is_success; 
+is $TestAppPluginWithNewMethod::MODIFIER_FIRED, 1, 'Before modifier was fired correctly.';