Fix a problem; roles with bare-attributes could affect cache invalidation
Fuji, Goro [Thu, 28 Oct 2010 12:47:16 +0000 (21:47 +0900)]
lib/Mouse/Meta/Class.pm
lib/Mouse/PurePerl.pm
xs-src/Mouse.xs

index 14a8762..20b2181 100644 (file)
@@ -241,7 +241,7 @@ sub add_attribute {
     # then register the attribute to the metaclass
     $attr->{insertion_order}   = keys %{ $self->{attributes} };
     $self->{attributes}{$name} = $attr;
-    delete $self->{_mouse_cache}; # clears internal cache
+    $self->_invalidate_metaclass_cache();
 
     if(!$attr->{associated_methods} && ($attr->{is} || '') ne 'bare'){
         Carp::carp(qq{Attribute ($name) of class }.$self->name
index dfee591..c0ec9a6 100644 (file)
@@ -339,6 +339,12 @@ sub is_immutable {  $_[0]->{is_immutable} }
 sub strict_constructor;
 *strict_constructor = $generate_class_accessor->('strict_constructor');
 
+sub _invalidate_metaclass_cache {
+    my($self) = @_;
+    delete $self->{_mouse_cache};
+    return;
+}
+
 sub _report_unknown_args {
     my($metaclass, $attrs, $args) = @_;
 
index 32ab97c..eff6ab7 100644 (file)
@@ -624,6 +624,19 @@ CODE:
     mouse_class_initialize_object(aTHX_ meta, object, args, is_cloning);
 }
 
+void
+_invalidate_metaclass_cache(SV* meta)
+CODE:
+{
+    AV* const xc = mouse_get_xc_if_fresh(aTHX_ meta);
+    if(xc) {
+        SV* const gen = MOUSE_xc_gen(xc);
+        sv_setuv(gen, 0U);
+    }
+    delete_slot(meta, newSVpvs_flags("_mouse_cache_", SVs_TEMP));
+}
+
+
 MODULE = Mouse  PACKAGE = Mouse::Meta::Role
 
 BOOT: