let reinitialization fix metaobjs via role reconciliation
[gitmo/Moose.git] / lib / Moose / Object.pm
index 6aee996..3f9d85b 100644 (file)
@@ -12,21 +12,17 @@ use Try::Tiny ();
 use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class';
 use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
 
-our $VERSION   = '0.94';
+our $VERSION   = '1.14';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 sub new {
     my $class = shift;
-
-    my $params = $class->BUILDARGS(@_);
-
     my $real_class = Scalar::Util::blessed($class) || $class;
-    my $self = Class::MOP::Class->initialize($real_class)->new_object($params);
 
-    $self->BUILDALL($params);
+    my $params = $real_class->BUILDARGS(@_);
 
-    return $self;
+    return Class::MOP::Class->initialize($real_class)->new_object($params);
 }
 
 sub BUILDARGS {
@@ -48,16 +44,13 @@ sub BUILDALL {
     # NOTE: we ask Perl if we even
     # need to do this first, to avoid
     # extra meta level calls
-    return if $_[0]->can('BUILD') == \&BUILD;
+    return unless $_[0]->can('BUILD');
     my ($self, $params) = @_;
     foreach my $method (reverse Class::MOP::class_of($self)->find_all_methods_by_name('BUILD')) {
-        next if $method->{class} eq __PACKAGE__;
         $method->{code}->execute($self, $params);
     }
 }
 
-sub BUILD { }
-
 sub DEMOLISHALL {
     my $self = shift;
     my ($in_global_destruction) = @_;
@@ -65,7 +58,7 @@ sub DEMOLISHALL {
     # NOTE: we ask Perl if we even
     # need to do this first, to avoid
     # extra meta level calls
-    return if $self->can('DEMOLISH') == \&DEMOLISH;
+    return unless $self->can('DEMOLISH');
 
     my @isa;
     if ( my $meta = Class::MOP::class_of($self ) ) {
@@ -81,15 +74,12 @@ sub DEMOLISHALL {
 
     foreach my $class (@isa) {
         no strict 'refs';
-        next if $class eq __PACKAGE__;
         my $demolish = *{"${class}::DEMOLISH"}{CODE};
         $self->$demolish($in_global_destruction)
             if defined $demolish;
     }
 }
 
-sub DEMOLISH { }
-
 sub DESTROY {
     my $self = shift;