Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I use an attribute modifer in Moose in a base class to handle multiple attributes from sub classes?
    text
    copied!<p>I've got several Modules that have a number of date time related attributes that accept a datestamp and return a human readable string ( dd Mon yyyy hh:mm:ss ).</p> <pre><code>package ModuleOne; use Moose; extends 'ModuleBase'; has date_attr_one =&gt; ( ... ); </code></pre> <p>and then ...</p> <pre><code>package ModuleTwo; use Moose; extends 'ModuleBase'; has date_attr_mouse =&gt; ( ... ); </code></pre> <p>As it's currently working I'm using an 'around' attribute modifier so that if there's no parameter return the a date in the format of '03 May 2012 12:33:42'. If there is a parameter in the format of '03 May 2012 12:33:42' the I want to set that as a datestamp.</p> <p>So, in ModuleOne, there would be:</p> <pre><code>has date_attr_one =&gt; ( ... ); </code></pre> <p>followed by:</p> <pre><code>around 'date_attr_one' =&gt; sub { ... } </code></pre> <p>Same type of thing occurs in the second module.</p> <p>The problem I'm having is that there are multiple modules doing this and each of them is using the 'around' modifier and the same duplicated code. I'd like to move that around modifier into the base class so every Module that extends the base class can use that modifier. I tried putting it into the base class using a regex like: (in the base class)</p> <pre><code>around qr/date_attr_one/ =&gt; sub { ... } </code></pre> <p>I put some print statements in there that never executed. Roles don't allow such a thing.</p> <p>Is there a way to move that around modifier into the base class so every Module that extends the base class can use that modifier where the attributes would have different names in each model? </p> <p>So, as in the example above, the base class' around attribute modifier would need to handle $self->date_attr_one and $self->date_attr_mouse, among others.</p>
 

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