in reply to Moose attribute: ro to public, rw in the class?
#!/usr/bin/perl use Modern::Perl; { package Foo; use Moose; has bar => ( is => 'ro', writer => '_set_bar', ); } my $foo = Foo->new; $foo->bar('something'); # outputs: # Cannot assign a value to a read-only accessor at # /home/brunov/tmp/pm.pl line 16 $foo->_set_bar('something'); say $foo->bar; # outputs: # something
Nothing stops your class' consumers from setting bar using _set_bar; they should follow the convention that methods with preceding underscores are private.
|
|---|