4 ms·
In Modern Perl (5) you use a module such as [Moose](https://metacpan.org/pod/Moose https://metacpan.org/pod/Moose) or if that's too heavy for you [Moo](https://
by lizmat 8y ago
In Modern Perl (5) you use a module such as [Moose](https://metacpan.org/pod/Moose https://metacpan.org/pod/Moose) or if that's too heavy for you [Moo](https://metacpan.org/pod/Moo https://metacpan.org/pod/Moo).
You rarely write accessor methods yourself in Perl 5. In Perl 6, you describe your accessors/mutators in the class definition:
class Pointer {
has $.x; # a ro accessor
has $.y is rw; # a rw mutator
}
Which, by the way, is now faster than Perl 5.
- vram22 8y ago> has $.x; # a ro accessor > has $.y is rw; # a rw mutator Opinion: I don't like the asymmetry of that, although I do understand that having to write "is ro" too, would make the language slightly more verbose. Python has something similar with the syntax for properties; don't like that syntax too, for the same reason (asymmetry). E.g.: The 2nd code example in the question here - https://stackoverflow.com/questions/17330160/how-does-the-property-decorator-work https://stackoverflow.com/questions/17330160/how-does-the-pr... - the one that uses @x.setter I'm not a language designer or close to it, though, just saying.
- b2gills 8y agoYou can always add `is ro` trait modifier. multi sub trait_mod:<is> (Attribute:D $attr, :$ro!) { # no need to do anything, because this is the default } class Pointer { has $.x is ro; has $.y is rw; } That is assuming you aren't fine with using `is readonly`. class Pointer { has $.x is readonly; has $.y is rw; } Which works better with the trait mod `is required` class Pointer { has $.x is readonly is required; has $.y is rw; }