From: Jesse Luehrs Date: Wed, 31 Mar 2010 20:10:10 +0000 (-0500) Subject: stick the call to BUILDALL in ->meta->new_object, rather than ->new X-Git-Tag: 1.04~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a19ae3d7d15eb6cf22ea979370957eb9e14e71d5;p=gitmo%2FMoose.git stick the call to BUILDALL in ->meta->new_object, rather than ->new --- diff --git a/Changes b/Changes index 789a9fa..a40a91d 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,9 @@ for, noteworthy changes. moved back up into Moose::Meta::Class and Moose::Meta::Role individually (through the Class::MOP::Mixin::HasMethods mixin) (doy). + * BUILDALL is now called by Moose::Meta::Class::new_object, rather than by + Moose::Object::new. (doy) + [BUG FIXES] * Fix has '+attr' in Roles to explode immediately, rather than when the role diff --git a/Makefile.PL b/Makefile.PL index a4af8ec..80c33be 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -55,7 +55,7 @@ sub check_conflicts { 'MooseX::Attribute::Prototype' => '0.10', 'MooseX::ClassAttribute' => '0.09', 'MooseX::MethodAttributes' => '0.18', - 'MooseX::NonMoose' => '0.05', + 'MooseX::NonMoose' => '0.07', 'MooseX::Params::Validate' => '0.05', 'MooseX::Role::Cmd' => '0.06', 'MooseX::Role::WithOverloading' => '0.04', diff --git a/lib/Moose/Manual/Delta.pod b/lib/Moose/Manual/Delta.pod index 2aef081..81e097a 100644 --- a/lib/Moose/Manual/Delta.pod +++ b/lib/Moose/Manual/Delta.pod @@ -16,6 +16,18 @@ feature. If you encounter a problem and have a solution but don't see it documented here, or think we missed an important feature, please send us a patch. +=over 4 + +=item L methods are now called when calling C + +Previously, C methods would only be called from C, +but now they are also called when constructing an object via +C. C methods are an inherent part of the +object construction process, and this should make C<< $meta->new_object >> +actually usable without forcing people to use C<< $meta->name->new >>. + +=back + =head1 1.02 =over 4 diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 0dd87c7..05da231 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -275,6 +275,8 @@ sub new_object { ); } + $self->BUILDALL($params) if $self->can('BUILDALL'); + return $self; } diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 14941b3..aacb0e1 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -18,15 +18,11 @@ 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 { diff --git a/t/050_metaclasses/052_new_object_BUILD.t b/t/050_metaclasses/052_new_object_BUILD.t new file mode 100644 index 0000000..b3bdd8c --- /dev/null +++ b/t/050_metaclasses/052_new_object_BUILD.t @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +my $called; +{ + package Foo; + use Moose; + + sub BUILD { $called++ } +} + +Foo->new; +is($called, 1, "BUILD called from ->new"); +$called = 0; +Foo->meta->new_object; +is($called, 1, "BUILD called from ->meta->new_object"); + +done_testing;