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

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Sun Dec 21 19:48:59 GMT 2008


Author: t0m
Date: 2008-12-21 19:48:59 +0000 (Sun, 21 Dec 2008)
New Revision: 8933

Added:
   Catalyst-Runtime/5.80/trunk/t/plugin_new_method_backcompat.t
Modified:
   Catalyst-Runtime/5.80/trunk/Changes
   Catalyst-Runtime/5.80/trunk/Makefile.PL
   Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Log:
C::P::A passes its tests against 5.80 now - fixed plugins having new methods by inlining a new method on MyApp.

Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes	2008-12-21 15:41:42 UTC (rev 8932)
+++ Catalyst-Runtime/5.80/trunk/Changes	2008-12-21 19:48:59 UTC (rev 8933)
@@ -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)

Modified: Catalyst-Runtime/5.80/trunk/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/trunk/Makefile.PL	2008-12-21 15:41:42 UTC (rev 8932)
+++ Catalyst-Runtime/5.80/trunk/Makefile.PL	2008-12-21 19:48:59 UTC (rev 8933)
@@ -6,6 +6,7 @@
 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';

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2008-12-21 15:41:42 UTC (rev 8932)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2008-12-21 19:48:59 UTC (rev 8933)
@@ -8,6 +8,7 @@
 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 @@
 
 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 @@
     }
     $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);
 }
 

Added: Catalyst-Runtime/5.80/trunk/t/plugin_new_method_backcompat.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/plugin_new_method_backcompat.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/plugin_new_method_backcompat.t	2008-12-21 19:48:59 UTC (rev 8933)
@@ -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.';




More information about the Catalyst-commits mailing list