in reply to Re: delegate Moose accessors to a HASH?
in thread delegate Moose accessors to a HASH?

The setter doesn't seem to work:
$foo->that(10) # sets $foo->data->{that} = 10

I can make this work:

$foo->that = 10
by adding :lvalue to the sub declarations, but that's not what I want.

Replies are listed 'Best First'.
Re^3: delegate Moose accessors to a HASH?
by ikegami (Patriarch) on Jun 23, 2011 at 19:59 UTC

    Sorry, I wrote it as a getter, not an accessor.

    handles => { this => sub { @_ == 1 ? $_[0]->data->{this} : $_[0]->data->{this} = $_[1] }, that => sub { @_ == 1 ? $_[0]->data->{that} : $_[0]->data->{that} = $_[1] }, },

    You can use a map to avoid duplication and/or an accessor generating function.