Hello kcott,

The former says it (i.e. the "XYZ") must be an object or class;

No, it says an object, or a class name. One might expect that the Perl interpreter would check that the name (i.e., string) supplied refers to an actual class/package, and in the normal case that is what happens, during method lookup. For example, Dog->bark() would be interpreted as a call to the bark method in the Dog class, so if there is no package Dog visible the lookup will result in a runtime error. (Likewise, if there is such a package but it doesn’t contain a bark method.)

But in the case in question — "XYZ"->$x("fred") — there is no lookup because the method to be invoked is fully specified by the coderef $x. And since there is no need for a method resolution, no check is done to verify that "XYZ" is a valid package/class name; instead, this string is simply passed through as the first argument to the method.

"I believe this parse option is needed to allow constructors to be called correctly."
I don't understand what you're referring to here. Could you expand upon this point. Thanks.

Nothing very profound. :-(  I was thinking of constructors, but I really should have said class methods generally (as opposed to object methods). Since in Perl a class/package is identified only by name, class methods are possible only if the parser recognises a form of method invocation in which the invoker is a class (package) name, i.e., a string. A constructor is just a special case of a class method.

Hence the "XYZ"->$x("fred") construct needs to be syntactically valid Perl. Whether "XYZ" is verified (necessarily at runtime) as a valid package name is an implementation detail. Choosing to validate class names only when necessary seems like a reasonable implementation choice for the parser.

Just my 2¢,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^7: Moose 'clone' Constructor by Athanasius
in thread Moose 'clone' Constructor by kcott

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.