And fixes for the CDI issue, this is getting really yucky..
Tomas Doran [Sat, 3 Jan 2009 13:30:18 +0000 (13:30 +0000)]
Changes
TODO
lib/Catalyst/ClassData.pm
t/cdi_backcompat_plugin_accessor_override.t

diff --git a/Changes b/Changes
index a604f43..cef7eba 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Fix plugins which hook onto setup_finished being called (t0m)
+          - Test for this (t0m)
         - Fix calling use Catalyst::Test 'MyApp' 'foo' which used to work,
           but stopped as the 2nd parameter can be an options hash now (t0m)
         - Bump Moose dependency to fix make_immutable bug (t0m)
diff --git a/TODO b/TODO
index 3b26ba3..44f794d 100644 (file)
--- a/TODO
+++ b/TODO
@@ -37,9 +37,10 @@ Back-compat investigation / known issues:
        Catalyst::Dispatcher::_do_forward does not fix arguments if you throw
        an exception. Needs a test case (Caelum)
      
-     - Catalyst::Plugin::Authentication::Store::DBIC fails as
-       overriding the setup_finished class data method in a plugin no longer
-       works correctly (see t/cdi_backcompat_accessor_override.t).
+     - Catalyst::Plugin::Authentication::Store::DBIC relies on 
+       hooking the setup_finished class data method in a plugin
+       (see t/cdi_backcompat_accessor_override.t).
+       Is this insane / should we support this?
 
   - Issues with TWMC not being loaded when it used to be in 5.70 
     (Bill Moseley)
index 6b14d7e..87b68c9 100644 (file)
@@ -14,8 +14,20 @@ sub mk_classdata {
   my $accessor =  sub {
     my $pkg = ref $_[0] || $_[0];
     my $meta = $pkg->Class::MOP::Object::meta();
-    if (@_ > 1){
+    if (@_ > 1) {
       $meta->namespace->{$attribute} = \$_[1];
+      no strict 'refs';
+      if (! *{"${pkg}::${attribute}"}{CODE} ) {
+        foreach my $super ( $meta->linearized_isa ) {
+          # If there is a code symbol for this class data in a parent class, but not in our 
+          # class then copy it into our package. This is evil.
+          my $parent_symbol = *{"${super}::${attribute}"}{CODE} ? \&{"${super}::${attribute}"} : undef;
+          if (defined $parent_symbol) {
+            *{"${pkg}::${attribute}"} = $parent_symbol;
+            last;
+          }
+        }      
+      }
       return $_[1];
     }
 
@@ -29,14 +41,6 @@ sub mk_classdata {
      return ${$v};
     } else {
       foreach my $super ( $meta->linearized_isa ) {
-        # If there is a code symbol for this attr in a parent class, 
-        # then copy it into our package. Is this the correct
-        # fix for C::D::I back-compat? (t0m)
-        my $parent_symbol = *{"${super}::${attribute}"}{CODE} ? \&{"${super}::${attribute}"} : undef;
-        # FIXME - this is over-enthusiastic?
-        if (defined $parent_symbol) {
-          *{"${pkg}::${attribute}"} = $parent_symbol;
-        }
         # tighter version of same after
         # my $super_meta = Moose::Meta::Class->initialize($super);
         my $v = ${"${super}::"}{$attribute} ? *{"${super}::${attribute}"}{SCALAR} : undef;
index 01ee258..bb6bddf 100644 (file)
@@ -30,9 +30,7 @@ lives_ok {
 
 # And the plugin's setup_finished method should have been run, as accessors
 # are not created in MyApp until the data is written to.
-TODO: {
-    local $TODO = "Copying the class data accessor down into MyApp other than at runtime\n" .
-    " when assigned (as pre exact CDI behavior) causes methods to not get run";
+{
     no warnings 'once';
     is $CDICompatTestPlugin::Data::HAS_RUN_SETUP_FINISHED, 1, 'Plugin setup_finish run';
 }