Why are you so hung up on this? It seems to be more or less a matter of taste. There are plenty of CPAN modules that take a list of raw name/value pairs, and plenty that take a hash reference instead.

As pointed out by ikegami, the way Moose does it is probably more efficient. OTOH, Perl Best Practices chapter nine ("Use a hash of named arguments for any subroutine that has more than three parameters") advises "as tempting as it may be, don't pass them as a list of raw name/value pairs". Conway recommends passing named arguments as a hash reference instead, because, as ikegami also noticed, doing so gives you a good chance of catching common blunders, such as the one made by the OP, at compile-time ("Odd number of elements in hash"), rather than run-time.

Update: As indicated at Named Subroutine Parameters: Compile-time errors vs. Run-time warnings, this "reason" was an error in the book: anonymous hash population is done at run-time, not compile-time. Conway still stands by the advice though because "Error messages that point users to the right place are definitely worth the (tiny) overhead of passing named args in a hash".

BTW, PBP chapter nine used to be the free sample chapter, but has now become a broken link. :-(


In reply to Re: Why Moose uses this syntax??!! by eyepopslikeamosquito
in thread Why Moose uses this syntax??!! by Anonymous Monk

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.