Search code examples
perlmoose

How can I use MooseX::ClassAttribute within a role?


I would like to use MooseX::ClassAttribute in a role. I.e., do something like

package Cachable;

use Moose::Role;
use MooseX::ClassAttribute;

class_has Cache => ( is => 'rw' );

1;

Unfortunately, the code above doesn't work as the deep magic of MooseX::ClassAttribute expects to be called from within a Moose object, and not a Moose::Role.
Is there any way to work around this, or is this a known limitation?


Solution

  • You send me a patch that makes this work. It's certainly doable, although the Moose internals make it harder than it needs to be because of how roles handle attributes.