This adds wrapper methods into your class to manipulate the underlying arrayref. I've given them sensible names too: add_thingies to push new elements to the end of the array, and list_thingies to return the list of values.package Wibble; use Moose; use MooseX::AttributeHelpers; has 'thingies' => ( metaclass => 'Collection::Array', is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, provides => { push => 'add_thingies', elements => 'list_thingies', }, );
Now you can add additional items like so:
The specific methods you can provide for ArrayRef attributes are listed in MooseX::AttributeHelpers::MethodProvider::List and MooseX::AttributeHelpers::MethodProvider::Array.my $w = Wibble->new( thingies => [ 'this', 'that' ]); print join(", ",$w->list_thingies())."\n"; # prints "this, that" # here's the bit that we just made work $w->add_thingies('another'); print join(", ",$w->list_thingies())."\n"; # prints "this, that, another"
I can also recommend the Moose::Manual. It's a nice overview of how Moose works, and describes some of the commonly used extensions.
In reply to Re: Moose Accessor Question
by rhesa
in thread Moose Accessor Question
by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |