On Tue, Jul 17, 2012 at 04:08:09AM -0700, Peter Shangov wrote: > Hi all, > > It appears that if I create an object with $metaclass->new_object(), > BUILDARGS will not be executed, e.g.: > > > { > package Foo; > use Moose 2.0603; > > sub BUILDARGS { warn "Building args"; return {} } > } > > Foo->new; # warns > Foo->meta->new_object; # doesn't > > The same does not apply to BUILD, which will be executed in both > cases. Is this the desired behaviour?
Yes, this is working as intended. The idea is that the method signature for the lower level new_object call should be fixed - it should take a hashref of init_args always, regardless of anything else that's going on (so that it's more predictable). If you want to fiddle with the API for how objects are constructed, you can change how ->new works in your own class, but metaclasses are used to describe many different classes. If this is an issue for you, Foo->meta->name->new(...) works fine. -doy