On Tue, Sep 08, 2009 at 05:08:07PM +0100, Mark Blackman wrote:
> Hi,
>
> A quick question on recommended practice here.
>
> One of my Moose-using package attributes is a hash reference.
>
> What's the recommended accessor technique for a key in that hash if
> I want a dedicated accessor/mutator for that key? a dedicated method?
> or something Moose-y?
>
> Provisos:
>
> a) I want several such accessors so cut-n-paste for a dedicated method
> is unattractive
>
> b) I do need the whole hash reference so it's not an option to hide
> it completely.
>
> $obj->hashrefattr({ foo => bar, joe => blow });
>
> I then want to be able to write
>
> $obj->foo and $obj->joe('bloggs');
>
> for reasons of brevity and readability.
>
> Obviously it's trivial to use $obj->hashrefattr->{foo}, but
> I'd like a dedicated accessor/mutator method for that key.
>
> - MarkIf you check out the latest (development) release, the Native attribute traits that we just added should do exactly this. We should be getting an actual release with this out within the next few days. If you need this now, the code came mostly from MooseX::AttributeHelpers, which should continue to work. -doy
