Audit and minimize use of last major indirect method: search()
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSourceProxy / Table.pm
index 53dd26f..4cb733f 100644 (file)
@@ -9,7 +9,6 @@ use DBIx::Class::ResultSource::Table;
 use Scalar::Util 'blessed';
 use namespace::clean;
 
-# FIXME - both of these *PROBABLY* need to be 'inherited_ro_instance' type
 __PACKAGE__->mk_classaccessor(table_class => 'DBIx::Class::ResultSource::Table');
 # FIXME: Doesn't actually do anything yet!
 __PACKAGE__->mk_group_accessors( inherited => 'table_alias' );
@@ -93,6 +92,29 @@ sub table {
       : undef
     ;
 
+    # Folks calling ->table on a class *might* expect the name
+    # to shift everywhere, but that can't happen
+    # So what we do is mark the ancestor as "dirty"
+    # even though it will have no "derived" link to the one we
+    # will use afterwards
+    if(
+      defined $ancestor
+        and
+      $ancestor->name ne $table
+        and
+      scalar $ancestor->__derived_instances
+    ) {
+      # Trigger the "descendants are dirty" logic, without giving
+      # it an explicit externally-callable interface
+      # This is ugly as sin, but likely saner in the long run
+      local $ancestor->{__in_rsrc_setter_callstack} = 1
+        unless $ancestor->{__in_rsrc_setter_callstack};
+      my $old_name = $ancestor->name;
+      $ancestor->set_rsrc_instance_specific_attribute( name => "\0" );
+      $ancestor->set_rsrc_instance_specific_attribute( name => $old_name );
+    }
+
+
     my $table_class = $class->table_class;
     $class->ensure_class_loaded($table_class);