From: Gordon Irving Date: Sat, 1 Aug 2009 23:37:49 +0000 (+0100) Subject: change new to only call BUILDCLASS and add a type safety check X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=577b4667d0feb743dad5a315ae7135d6cb581405;p=gitmo%2FMoose.git change new to only call BUILDCLASS and add a type safety check --- diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 49f804a..1822523 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -26,8 +26,12 @@ sub new { # this provides a hook to allow subclasses, roles, traits etc a chance to change # how the class will behave - my $built_class = $real_class->BUILDALLCLASS($params); + my $built_class = $real_class->BUILDCLASS($params); + # type safety check + unless ( $built_class->isa($real_class) ) { + Class::MOP::class_of($class)->throw_error("BUILDCLASS returned a class not derrived from $class"); + } my $self = Class::MOP::Class->initialize($built_class)->new_object($params); $self->BUILDALL($params); @@ -62,16 +66,9 @@ sub BUILDALL { } -sub BUILDALLCLASS { - # NOTE: we ask Perl if we even - # need to do this first, to avoid - # extra meta level calls - return $_[0] unless $_[0]->can('BUILDCLASS'); - my ($class, $params) = @_; - foreach my $method (reverse Class::MOP::class_of($class)->find_all_methods_by_name('BUILDCLASS')) { - $class = $method->{code}->execute($class, $params); - } - return $class; +sub BUILDCLASS { + # real simple, just here to provide a hook + shift; } sub DEMOLISHALL {