I'm not sure what choroba said in response to this question, and these comments are in the context of general Perl OO practice and not Moo, but ...

... "Does $self->new make sense?" ...

I sometimes see constructor code that looks something like

sub new { my $class_or_objref = shift; my $ref_class = ref $class_or_objref; # true if an object referen +ce my $object_reference; if ($ref_class) { # build object reference from existing object attributes # and supplied @_ arguments. } else { # build object reference for class from supplied @_ arguments. } return $object_reference; }
To me, this factors naturally as
sub new { my $classname_or_objref = shift; return ref $classname_or_objref ? $classname_or_objref->new_clone + (@_) : $classname_or_objref->new_pristi +ne(@_) ; }
(Update: From this point on, @_ | no, changed my mind, will use ... (yada) for this notation represents a general argument LIST, possibly empty.)
So every class/package may potentially need both a
    $object_reference->new_clone(...)
method that builds and returns a new object reference based on the attributes of an existing object and any additional arguments supplied, and a traditional
    ClassName->new_pristine(...)
method that builds and returns a new object reference based solely on a class name bareword/string and any arguments. It's immediately obvious that
    ClassName->new_pristine(...)
looks a lot like the very familiar
    ClassName->new(...)
usage, and
    $object_reference->new_clone(...)
can very intuitively be represented simply as
    $object_reference->clone(...)

IMHO, there is no value added by trying to combine object clone creation with "classic" object construction. The calls
    my $obj = ClassName->new(...);
and
    my $obj = $existing_object_reference->clone(...);
should do exactly what you expect them to do and no more. A  ClassName->new constructor definition can often be very short, sweet and easy to understand; don't clutter it up with unnecessary stuff. If no  clone() constructor is needed for a class (and it usually isn't), don't define one. So, in answer to the question,  $self->new can make sense, but usually doesn't, and certainly not with that method name.

... does Perl have something similar to new XYZ; which will search for the nearest new() all the way up the inheritance tree of XYZ?

IIRC, any  ClassName->method() or  $objref->method() call will search for method() first in the specified class (either explicitly named or embedded in the object reference) and then all the way up the @ISA tree of the specified class under the control of the mro (available with Perl version 5.10+) currently selected, and then into the UNIVERSAL class. (And, of course, new has the same status as any other method name. It is used as a constructor name by convention; any other — well documented! — name could be used.)


Give a man a fish:  <%-{-{-{-<


In reply to Re^7: Rename a Moo constructor from "new" to "run" by AnomalousMonk
in thread Rename a Moo constructor from "new" to "run" by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.