From: Shawn M Moore Date: Sat, 28 Mar 2009 21:14:28 +0000 (-0400) Subject: Need to handle $self->new just as well as $class->new X-Git-Tag: 0.73_01~36^2~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2eaf25da697f64a86ffce9f0f023c78541631e68;p=gitmo%2FMoose.git Need to handle $self->new just as well as $class->new --- diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 8398099..0d2aa9c 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -4,6 +4,8 @@ package Moose::Object; use strict; use warnings; +use Scalar::Util; + use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class'; use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class'; @@ -13,9 +15,16 @@ our $AUTHORITY = 'cpan:STEVAN'; sub new { my $class = shift; + my $params = $class->BUILDARGS(@_); - my $self = Class::MOP::Class->initialize($class)->new_object($params); + + # We want to support passing $self->new, but initialize + # takes only an unblessed class name + my $real_class = Scalar::Util::blessed($class) || $class; + my $self = Class::MOP::Class->initialize($real_class)->new_object($params); + $self->BUILDALL($params); + return $self; }