|| $class->construct_class_instance(package => $package_name, @_);
}
-sub reinitialize {
- my $class = shift;
- my $package_name = shift;
- (defined $package_name && $package_name && !blessed($package_name))
- || confess "You must pass a package name and it cannot be blessed";
- Class::MOP::remove_metaclass_by_name($package_name);
- $class->construct_class_instance('package' => $package_name, @_);
-}
-
# NOTE: (meta-circularity)
# this is a special form of &construct_instance
# (see below), which is used to construct class
my $current = Class::MOP::check_package_cache_flag($self->name);
if (defined $self->{'_package_cache_flag'} && $self->{'_package_cache_flag'} == $current) {
- return $self->{'methods'};
+ return $self->{'methods'} ||= {};
}
$self->{_package_cache_flag} = $current;
- my $map = $self->{'methods'};
+ my $map = $self->{'methods'} ||= {};
my $class_name = $self->name;
my $method_metaclass = $self->method_metaclass;
return;
}
+# check if we can reinitialize
+sub is_pristine {
+ my $self = shift;
+
+ # if any local attr is defined
+ return if $self->get_attribute_list;
+
+ # or any non-declared methods
+ if ( my @methods = values %{ $self->get_method_map } ) {
+ my $metaclass = $self->method_metaclass;
+ foreach my $method ( @methods ) {
+ return if $method->isa("Class::MOP::Method::Generated");
+ # FIXME do we need to enforce this too? return unless $method->isa($metaclass);
+ }
+ }
+
+ return 1;
+}
+
## Class closing
sub is_mutable { 1 }
This initializes and returns returns a B<Class::MOP::Class> object
for a given a C<$package_name>.
-=item B<reinitialize ($package_name, %options)>
-
-This removes the old metaclass, and creates a new one in it's place.
-Do B<not> use this unless you really know what you are doing, it could
-very easily make a very large mess of your program.
-
=item B<construct_class_instance (%options)>
This will construct an instance of B<Class::MOP::Class>, it is
This returns true if the class has been made immutable.
+=item B<is_pristine>
+
+Checks whether the class has any data that will be lost if C<reinitialize> is
+called.
+
=back
=head2 Inheritance Relationships