如何在角色中使用 MooseX::ClassAttribute?
我想用 MooseX::ClassAttribute 中 一名角色。 即,执行类似的操作
package Cachable;
use Moose::Role;
use MooseX::ClassAttribute;
class_has Cache => ( is => 'rw' );
1;
不幸的是,上面的代码不起作用 MooseX::ClassAttribute 的深层魔力期待 从 Moose 对象内部调用,而不是 Moose::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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你给我发了一个补丁,可以让这个工作正常进行。 这当然是可行的,尽管 Moose 内部由于角色处理属性的方式而使其变得比实际需要的更加困难。
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.