I have made it a practice to always use MooseX::StrictConstructor in my code, mainly because I got bit by a typo in a constructor attribute once. After that happened, I suggested to my team that we adopt this as a "best practice" policy but was voted down. One of the reasons being that if I wanted something like that I should be using Java, not Perl.

Granted, that is an argument I have used in the past, mainly to object to inside-out objects. (And I still object to them, but at least they seem to be a moot point today.)

However, I don't think that argument applies in this case. Nobody would argue that use strict; takes away from the spirit of Perl. And if one bears in mind that use Moose; automatically sets strictures then it seems that having strict constructor attributes would be a natural extension of that.

I can't think of any case where the ability to send a parameter in the constructor that could be handled only by say BUILDARGS or BUILD would outweigh the protection against a typo in a hash key. If anything, it seems to me that not having attributes declared in a has statement goes against the very purpose of using Moose in the first place.

My question is this: Does the use of MooseX::StrictConstructor move Perl in a direction that is more in line with strongly typed languages, or is it such common sense that the Moose Cabal should consider making it an automatic feature of Moose itself?

Update: minor grammar corrections, added CPAN links as needed.

It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

In reply to Should MooseX::StrictConstructor be part of Moose itself? by boftx

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.