Is there a good way of making all the object attributes readonly in Moo? Something that would allow me to replace:
package Foo { use Moo; has 'attr_A' => ( is => 'ro', default => sub { 'A' } ); has 'attr_B' => ( is => 'ro', default => sub { 'B' } ); has 'attr_C' => ( is => 'ro', isa => sub { die unless $_[0] > 0 } +); }
With something like:
package Foo { use Moo; # this is where the magic happens has 'attr_A' => ( default => sub { 'A' } ); has 'attr_B' => ( default => sub { 'B' } ); has 'attr_C' => ( isa => sub { die unless $_[0] > 0 } ); }
There is an interesting blog post by mascip, about the possibility of enabling immutability for all the objects of a given class. The post refers to Moose, and its author seems to ask about a stronger restriction - making the object truly immutable. I'm only looking for some way to make the is => 'ro' a default for all the attributes of a given class. Still, I wanted to link this post here since it provides a good explanation for the reasoning behind my question.
One 'bad way' I can think of would be using Filter::Simple, but I hope to find another way to do it. Humbly seeking your advice.
- Luke
In reply to Making 'all' the attributes read only by default (Moo) by blindluke
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |