From: Yuval Kogman Date: Fri, 15 Aug 2008 18:55:34 +0000 (+0000) Subject: is_pristine X-Git-Tag: 0_64_01~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc67d48ac61db2a8bbccb6c70c960d06bd9183ad;p=gitmo%2FClass-MOP.git is_pristine --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 83088da..d409156 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -980,6 +980,25 @@ sub find_attribute_by_name { 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 } @@ -1375,6 +1394,11 @@ This returns true if the class is still mutable. This returns true if the class has been made immutable. +=item B + +Checks whether the class has any data that will be lost if C is +called. + =back =head2 Inheritance Relationships diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 9eee7af..3b84c34 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 230; +use Test::More tests => 232; use Test::Exception; BEGIN { @@ -50,6 +50,8 @@ my @class_mop_module_methods = qw( my @class_mop_class_methods = qw( _new + is_pristine + initialize create update_package_cache_flag