perl5ever has asked for the wisdom of the Perl Monks concerning the following question:
package Foo; use Moose; has data (is => 'rw');
The 'data' field is meant to populated with a hash ref.
Is is possible to delegate some accessors of Foo to the 'data' hash ref. E.g.:
The delegated fields will be known in advance.my $foo = Foo->new(data => { this => 1, that => 2 }); $foo->this # returns $foo->data->{this} $foo->that(10) # sets $foo->data->{that} = 10
It seems that Moose::Meta::Attribute::Native is somewhat relevant here, but I don't see how it would be done.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: delegate Moose accessors to a HASH?
by ikegami (Patriarch) on Jun 23, 2011 at 19:26 UTC | |
by perl5ever (Pilgrim) on Jun 23, 2011 at 19:42 UTC | |
by ikegami (Patriarch) on Jun 23, 2011 at 19:59 UTC |