如何使用鼠标委托数组的第一个元素?
我有一个包含一堆对象的对象。该对象表示当前状态,堆栈中的每个对象都保存特定嵌套级别的状态。
package State;
use Mouse;
use RealState;
has state_stack => {
is => 'rw',
isa => 'ArrayRef[RealState]',
default => sub {
return [RealState->new]
}
};
我希望 State 委托给 State->state_stack->[0]
。我怎样才能用鼠标有效地做到这一点(所以没有元黑客攻击)。我无法使用 Moose,我的项目 不能有任何依赖项(我正在捆绑 Mouse::Tiny) 。
“你不能”没关系,我会写一个AUTOLOAD
。
I have an object which holds a stack of objects. The object represents the current state, and each object in the stack holds the state at a particular level of nesting.
package State;
use Mouse;
use RealState;
has state_stack => {
is => 'rw',
isa => 'ArrayRef[RealState]',
default => sub {
return [RealState->new]
}
};
I want State to delegate to State->state_stack->[0]
. How can I do that efficiently with Mouse (so no meta hacking). I cannot use Moose, my project cannot have any dependencies (I'm bundling Mouse::Tiny).
"You can't" is fine, I'll write an AUTOLOAD
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能直接这样做,但有一个比自动加载更好的技巧。也就是说,RealState->meta->get_all_method_names() 为您提供 RealState 中定义的方法名称。
You can't it directly, but there's a hack better than AUTOLOAD. That is, RealState->meta->get_all_method_names() gives you method names which are defined in RealState.