From: Yuval Kogman <nothingmuch@woobling.org>
Date: Sat, 9 Aug 2008 08:16:35 +0000 (+0000)
Subject: clean up the mess after a failed attribute addition
X-Git-Tag: 0_64_01~61
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=961ff82f50f5fa7d2e4a67e0bb4693b648d00047;p=gitmo%2FClass-MOP.git

clean up the mess after a failed attribute addition
---

diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm
index d994d20..479fc78 100644
--- a/lib/Class/MOP/Class.pm
+++ b/lib/Class/MOP/Class.pm
@@ -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;
 }