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};
# all these attribute readers will be bootstrapped
# away in the Class::MOP bootstrap section
-sub name { $_[0]->{'$!package'} }
+sub name { $_[0]->{'$!package'} }
sub namespace {
# NOTE:
# because of issues with the Perl API
# we could just store a ref and it would
# Just Work, but oh well :\
no strict 'refs';
- \%{$_[0]->name . '::'}
+ \%{$_[0]->{'$!package'} . '::'}
}
# utility methods
no strict 'refs';
no warnings 'redefine', 'misc';
- *{$self->name . '::' . $name} = ref $initial_value ? $initial_value : \$initial_value;
+ *{$self->{'$!package'} . '::' . $name} = ref $initial_value ? $initial_value : \$initial_value;
}
sub remove_package_glob {