From: Yuval Kogman <nothingmuch@woobling.org>
Date: Fri, 8 Aug 2008 23:25:26 +0000 (+0000)
Subject: Bootstrap Instance to have a proper constructor
X-Git-Tag: 0_64_01~68
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=caa051faf6e0971c6e4d7bd240dba41265a5d52e;p=gitmo%2FClass-MOP.git

Bootstrap Instance to have a proper constructor
---

diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm
index ed5195f..451a5ee 100644
--- a/lib/Class/MOP.pm
+++ b/lib/Class/MOP.pm
@@ -722,23 +722,6 @@ Class::MOP::Method::Constructor->meta->add_method('new' => sub {
 # these don't yet do much of anything, but are just
 # included for completeness
 
-#Class::MOP::Instance->meta->add_method('new' => sub {
-#    my $class   = shift;
-#    my $options = $class->BUILDARGS($class);
-#
-#    # return the new object
-#    my $self = $class->meta->new_object(%$options);
-#    
-#    # we don't want this creating
-#    # a cycle in the code, if not
-#    # needed
-#    Scalar::Util::weaken($self->{'associated_metaclass'});
-#
-#    $self->initialize_body;  
-#    
-#    $self;
-#});
-
 Class::MOP::Instance->meta->add_attribute(
     Class::MOP::Attribute->new('associated_metaclass')
 );
@@ -752,6 +735,24 @@ Class::MOP::Instance->meta->add_attribute(
 );
 
 
+# we need the meta instance of the meta instance to be created now, in order
+# for the constructor to be able to use it
+Class::MOP::Instance->meta->get_meta_instance;
+
+Class::MOP::Instance->meta->add_method('new' => sub {
+    my $class   = shift;
+    my $options = $class->BUILDARGS(@_);
+
+    my $self = $class->meta->new_object(%$options);
+    
+    Scalar::Util::weaken($self->{'associated_metaclass'});
+
+    $self;
+});
+
+# pretend the add_method never happenned. it hasn't yet affected anything
+undef Class::MOP::Instance->meta->{_package_cache_flag};
+
 ## --------------------------------------------------------
 ## Now close all the Class::MOP::* classes