In Moose we can put restrictions on instance attributes or add getters/setters like so:
has 'color' => (
is => 'rw',
isa => 'Str',
writer => '_set_color',
);
has ['color', 'temperature', 'size'] => (
is => 'rw',
isa => 'Str',
);
_set_color
_set_temperature
_set_size
bad accessor/reader/writer/predicate/clearer format, must be a HASH
ref
has ['color', 'temperature', 'size'] => (
is => 'rw',
isa => 'Str',
writer => sub {
print Dumper(\@_);
return;
);
has ['color', 'temperature', 'size'] => (
is => 'rw',
isa => 'Str',
writer => "_set_$_";
);
has
isn't magic. It's just a subroutine call. So something like this should work (untested):
for (qw[colour temperature size]) {
has $_ => (
is => 'rw',
isa => 'Str',
writer => "_set_$_",
);
}