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.
And the output: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";
Moose doesn't offer lvalue accessors, which I believe is a deliberate choice.My things are: blue green green yellow My things are now: blue green green yellow mango
stephen
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using ArrayRef data members in Moose
by stvn (Monsignor) on Jul 04, 2008 at 03:39 UTC | |
Re^2: Using ArrayRef data members in Moose
by window_breaker (Sexton) on Sep 24, 2010 at 18:44 UTC |
In Section
Seekers of Perl Wisdom