Moose documentation表示我可以轻松地委托给对象thing
。
has 'thing' => (
...
handles => { set_foo => [ set => 'foo' ] },
);
# $self->set_foo(...) calls $self->thing->set('foo', ...)
但我真的想委托一个关于thing的对象,特别是一个datetime对象
has 'thing' => (
...
handles => {
get_month => { datetime ... },
},
);
# $self->get_month calls $self->thing->datetime->month;
如何构建句柄以使其执行此操作?
答案 0 :(得分:3)
has thing => (
...
handles => {
get_month => sub { $_[0]->thing->datetime->month },
},
);
如果不将datetime_month
添加到thing
,则必须编写自己的委托人。