clean up the mess after a failed attribute addition
Yuval Kogman [Sat, 9 Aug 2008 08:16:35 +0000 (08:16 +0000)]
lib/Class/MOP/Class.pm

index d994d20..479fc78 100644 (file)
@@ -831,7 +831,11 @@ sub add_attribute {
     $self->get_attribute_map->{$attribute->name} = $attribute;
 
     # invalidate package flag here
-    $attribute->install_accessors();
+    my $e = do { local $@; eval { $attribute->install_accessors() }; $@ };
+    if ( $e ) {
+        $self->remove_attribute($attribute->name);
+        die $e;
+    }
 
     return $attribute;
 }