1

Mooseドキュメントによると、オブジェクトthingに簡単に委譲できるとのことです。

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

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

しかし、私は本当に物のオブジェクト、特にdatetimeオブジェクトに委任したい

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_monthするthingだけでなく、独自のデリゲータを作成する必要があります。

于 2012-05-14T02:59:05.900 に答える