http://www.perlmonks.org?node_id=695498


in reply to Using ArrayRef data members in Moose

I understand that you want to avoid using extension modules, but in this case AttributeHelpers does almost exactly what you want.
package Holder; use Moose; use MooseX::AttributeHelpers; has 'things' => ( metaclass => 'Collection::Array', is => 'rw', isa => 'ArrayRef[Str]', default => sub { [qw/blue green green yellow/] }, auto_deref => 1, provides => { 'push' => 'add_things' }, ); package main; my $holder = Holder->new(); print "My things are:\t\t", join(' ', $holder->things() ), "\n"; $holder->add_things('mango'); print "My things are now:\t", join(' ', $holder->things() ), "\n";
And the output:
My things are: blue green green yellow My things are now: blue green green yellow mango
Moose doesn't offer lvalue accessors, which I believe is a deliberate choice.

stephen