don't let anon classes disappear while subclasses still exist
Jesse Luehrs [Fri, 1 Oct 2010 00:26:28 +0000 (19:26 -0500)]
lib/Class/MOP/Class.pm
t/010_self_introspection.t
t/048_anon_class_create_init.t

index 1b09a81..6199b49 100644 (file)
@@ -860,6 +860,16 @@ sub superclasses {
 sub _superclasses_updated {
     my $self = shift;
     $self->update_meta_instance_dependencies();
+    # keep strong references to all our parents, so they don't disappear if
+    # they are anon classes and don't have any direct instances
+    $self->_superclass_metas(
+        map { Class::MOP::class_of($_) } $self->superclasses
+    );
+}
+
+sub _superclass_metas {
+    my $self = shift;
+    $self->{_superclass_metas} = [@_];
 }
 
 sub subclasses {
index 7c0a962..159f90e 100644 (file)
@@ -87,7 +87,7 @@ my @class_mop_class_methods = qw(
     invalidate_meta_instances invalidate_meta_instance
 
     superclasses subclasses direct_subclasses class_precedence_list
-    linearized_isa _superclasses_updated
+    linearized_isa _superclasses_updated _superclass_metas
 
     alias_method get_all_method_names get_all_methods compute_all_applicable_methods
         find_method_by_name find_all_methods_by_name find_next_method_by_name
index aa71442..a1cbb23 100644 (file)
@@ -82,10 +82,8 @@ my $instance;
         superclasses => [Class::MOP::Class->create_anon_class->name],
     );
     my @superclasses = $submeta->superclasses;
-    { local $TODO = "anon class ancestry isn't preserved yet";
     ok(Class::MOP::class_of($superclasses[0]),
        "superclasses are kept alive by their subclasses");
-    }
 }
 
 {