Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the best way to assign a method body at construction time when using Moose?
    primarykey
    data
    text
    <p>I'm using <code>Moose</code> (specifically <code>MooseX::Declare</code>) to create an iterator object, <code>Iter</code> which has a <code>next</code> method that advances state and returns <code>0</code> or <code>1</code> as required for use in a <code>while</code> statement. The problem I'm running into is that depending on the existence of one of the construction parameters, <code>next</code> needs to perform two very different sets of operations. The way I see it I have five options:</p> <ol> <li>if ... then in <code>next</code> method </li> <li>subclass</li> <li>hash dispatch</li> <li>symbol table manipulation</li> <li>put methods in different modules and load required one at construction time</li> </ol> <p><strong>Number 1</strong> is just amateur.</p> <p><strong>Number 2</strong> is, I suppose, the proper OOP way of doing things. I have no objections to doing it that way but seems a little bit overkill simply to override a single method. </p> <p>I've often used <strong>Number 3</strong> in the past when working procedurally or pseudo-functionally and it's what I'm doing now.</p> <p><strong>Number 4</strong> is, as we all know, fraught with peril and I know nothing about Moose Guts to want to start messing around when unnecessary.</p> <p>The last item, <strong>number 5</strong> seems to me to be the most sensible (and Perlish) but like Number 2, is a little too much work. I'm really wondering if there's a fifth way I haven't considered such as hooking into the metaclass or perhaps a <code>MooseX</code> module that is reasonably mature.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload