http://www.perlmonks.org?node_id=957219


in reply to Re^6: Perl "new" command
in thread Perl "new" command

... Now what? ...

can be replaced by:

bless do { my %self = (%{Colour->new($colour)}, %{Age->new($age)}); \% +self }, $class;

Moose (and some of its imitators) thankfully handles all of this for you. The Moose philosophy is to never write your own new method - rely on Moose to take care of it for you. If you do need to do some initialisation, then create a BUILD method - no matter how complex the inheritance you're using, Moose should call all the BUILD methods in a sane order.

The other solution is to go the inside-out object route. If your class doesn't care about the contents of the reference, then all is fine and dandy. The reference doesn't even have to be a hash/array any more - it could be a scalarref, a coderef, a quoted regexp, etc. Inside-out objects have been traditionally fiddly to write without leaking memory, but the recent "fieldhashes" modules have made it a lot easier.