|go ahead... be a heretic|
Should MooseX::StrictConstructor be part of Moose itself?by boftx (Deacon)
|on Nov 14, 2013 at 03:54 UTC||Need Help??|
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.