Bump to 0.63
[gitmo/Class-MOP.git] / lib / Class / MOP / Immutable.pm
index 289a2d5..8a57479 100644 (file)
@@ -9,7 +9,7 @@ use Class::MOP::Method::Constructor;
 use Carp         'confess';
 use Scalar::Util 'blessed';
 
-our $VERSION   = '0.06';
+our $VERSION   = '0.63';
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Class::MOP::Object';
@@ -114,20 +114,27 @@ sub make_metaclass_immutable {
 
         my $destructor_class = $options{destructor_class};
 
-        my $destructor = $destructor_class->new(
-            options      => \%options,
-            metaclass    => $metaclass,
-            package_name => $metaclass->name,
-            name         => 'DESTROY'            
-        );
-
-        $metaclass->add_method('DESTROY' => $destructor)
-            # NOTE:
-            # we allow the destructor to determine
-            # if it is needed or not, it can perform
-            # all sorts of checks because it has the
-            # metaclass instance
-            if $destructor->is_needed;
+        # NOTE:
+        # we allow the destructor to determine
+        # if it is needed or not before we actually 
+        # create the destructor too
+        # - SL
+        if ($destructor_class->is_needed($metaclass)) {
+            my $destructor = $destructor_class->new(
+                options      => \%options,
+                metaclass    => $metaclass,
+                package_name => $metaclass->name,
+                name         => 'DESTROY'            
+            );
+
+            $metaclass->add_method('DESTROY' => $destructor)
+                # NOTE:
+                # we allow the destructor to determine
+                # if it is needed or not, it can perform
+                # all sorts of checks because it has the
+                # metaclass instance
+                if $destructor->is_needed;
+        }
     }
 
     my $memoized_methods = $self->options->{memoize};