Hm, I am not a student of OOP theory, but I find that "most of what Moo faciliates" is not so much in the instance constructor but in attribute declarations, of which I typically have many times more than constructor params. I find that triggers, clearers, predicates and lazy builders etc. are among the main features of the framework, and they are for all attributes declared.
I don't normally find a problem with having a RO "accessor" derived from declaring an attribute in order to take a named constructor param, but if you really don't want its value to be available to consumers you could maybe do something with BUILDARGS?
Output:package Foo { use Moo; has qux => (is => 'ro'); around BUILDARGS => sub { my ($orig, $class, $args) = @_; return { qux => $args->{bar} * $args->{baz}, }; }; }; use strict; use warnings; use feature 'say'; my $o = Foo->new({ bar => 6, baz => 7, }); say $o->qux; say $o->bar;
$ perl 11107488.pl 42 Can't locate object method "bar" via package "Foo" at 11107488.pl line + 24.
Hope this helps!
In reply to Re^4: If Perl 5 were to become Perl 7, what (backward-compatible) features would you want to see?
by 1nickt
in thread If Perl 5 were to become Perl 7, what (backward-compatible) features would you want to see?
by haukex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |