1

Moose 文档说我可以很容易地委托给对象thing

has 'thing' => (
   ...
   handles => { set_foo => [ set => 'foo' ] },
);

# $self->set_foo(...) calls $self->thing->set('foo', ...)

但我真的想委托给一个对象,特别是一个日期时间对象

has 'thing' => (
   ...
   handles => {
       get_month => { datetime ... },
   },
);

# $self->get_month calls $self->thing->datetime->month;

我将如何构建句柄才能让它做到这一点?

4

1 回答 1

3
has thing => (
   ...
   handles => {
      get_month => sub { $_[0]->thing->datetime->month },
   },
);

除了添加datetime_monthtothing之外,您还必须编写自己的委托人。

于 2012-05-14T02:59:05.900 回答