perlmeditation
boftx
<p>
It has taken me a while to come around to the position that using code such as that in the title (or similar) is really cargo-cult programming. Given that seems to be the case, then I was somewhat dismayed to see that [mod://Moo] automatically includes such when it generates a constructor.
</p>
<p>
I initially got around this by using <c>before new</c> to detect the presence of a ref instead of a string and issuing an appropriate <c>croak</c> message. (tip of the hat to the folks on #moose for that!)
</p>
<p>
However, several others on #moose, notably some of the authors of Moo, said that was not a wise practice, and indeed, I found that the code was position dependent in relation to where <c>BUILDARGS</c> is defined. Specifically, the code for <c>before new</c> <b>must</b> come after <c>BUILDARGS</c> is defined or else the return value from that gets blown away.
</p>
<p>
After asking a couple of questions, and getting the expected response of "Well, write it yourself!" I decided to do just that. I have a working patch to Moo that disables the code in question, replacing it with an exception.
</p>
<p>
My question at this point is this: Is the ability to force a constructor to be a "class only" method a viable feature to have in Moo (and be extension, Moose)?
</p>
<p>
The solution I arrived at after reading the code for Moo and a few other MooX modules led me to use an option passed into Moo's <c>import</c> method. This was mainly due to the fact that other than a significant refactoring of [mod://Method::Generate::Constructor] it does not seem feasible to alter the code being generated.
</p>
<p>
While I am waiting for a review of my proposed patch, I'd like to hear the thoughts of my fellow monks if this is a desirable option to have.
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-1049510">
You must always remember that the primary goal is to <b><i>drain the swamp</i></b> even when you are hip-deep in alligators.
</div></div>