From: Jesse Luehrs Date: Fri, 1 Oct 2010 00:26:28 +0000 (-0500) Subject: don't let anon classes disappear while subclasses still exist X-Git-Tag: 1.10~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a5be8918f4208949883336b0248c69d00bc1c0e4;p=gitmo%2FClass-MOP.git don't let anon classes disappear while subclasses still exist --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 1b09a81..6199b49 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -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 { diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 7c0a962..159f90e 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -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 diff --git a/t/048_anon_class_create_init.t b/t/048_anon_class_create_init.t index aa71442..a1cbb23 100644 --- a/t/048_anon_class_create_init.t +++ b/t/048_anon_class_create_init.t @@ -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"); - } } {