bump version to 0.71_02 and update Changes
[gitmo/Class-MOP.git] / lib / Class / MOP / Immutable.pm
index eda19ba..e1493cb 100644 (file)
@@ -9,7 +9,7 @@ use Class::MOP::Method::Constructor;
 use Carp         'confess';
 use Scalar::Util 'blessed';
 
-our $VERSION   = '0.71_01';
+our $VERSION   = '0.71_02';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -36,6 +36,7 @@ sub new {
         'metaclass'           => $metaclass,
         'options'             => $options,
         'immutable_metaclass' => undef,
+        'inlined_constructor' => undef,
     );
 
     return $self;
@@ -58,6 +59,7 @@ sub immutable_metaclass {
 
 sub metaclass           { (shift)->{'metaclass'}           }
 sub options             { (shift)->{'options'}             }
+sub inlined_constructor { (shift)->{'inlined_constructor'} }
 
 sub create_immutable_metaclass {
     my $self = shift;
@@ -147,17 +149,18 @@ sub _inline_constructor {
     my $constructor_class = $options->{constructor_class}
         || 'Class::MOP::Method::Constructor';
 
-    $metaclass->add_method(
-        $options->{constructor_name},
-        $constructor_class->new(
-            options      => $options,
-            metaclass    => $metaclass,
-            is_inline    => 1,
-            package_name => $metaclass->name,
-            name         => $options->{constructor_name}
-        )
+    my $constructor = $constructor_class->new(
+        options      => $options,
+        metaclass    => $metaclass,
+        is_inline    => 1,
+        package_name => $metaclass->name,
+        name         => $options->{constructor_name},
     );
 
+    if ( $options->{replace_constructor} or $constructor->can_be_inlined ) {
+        $metaclass->add_method( $options->{constructor_name} => $constructor );
+        $self->{inlined_constructor} = $constructor;
+    }
 }
 
 sub _inline_destructor {
@@ -358,8 +361,11 @@ sub make_metaclass_mutable {
     # 14:27 <@stevan> so I am not worried
     if ($options{inline_constructor}  && $immutable->has_method($options{constructor_name})) {
         my $constructor_class = $options{constructor_class} || 'Class::MOP::Method::Constructor';
-        $immutable->remove_method( $options{constructor_name}  )
-          if blessed($immutable->get_method($options{constructor_name})) eq $constructor_class;
+
+        if ( blessed($immutable->get_method($options{constructor_name})) eq $constructor_class ) {
+            $immutable->remove_method( $options{constructor_name}  );
+            $self->{inlined_constructor} = undef;
+        }
     }
 }
 
@@ -456,6 +462,11 @@ This will change the C<$metaclass> into the mutable version by reversing
 the immutable process. C<%options> should be the same options that were
 given to make_metaclass_immutable.
 
+=item B<inlined_constructor>
+
+If the constructor was inlined, this returns the constructor method
+object that was created to do this.
+
 =back
 
 =head1 AUTHORS