Actually, you would. You do not want car odometers with some knobs that allows the driver to change the value. The external API of a car odometer does not have a setter - the driver can look at the display and see the value; he cannot set it. (Day trip meters are an intermediate - they allow display, and they have a reset function, but still, the driver cannot set it to an arbitrary value). Now, the driver can drive the car, and that will cause the attribute to change, but that's not setting a value of an attribute using a set-accessor. | [reply] |
Now, the driver can drive the car, and that will cause the attribute to change,
No, not without an accessor it won't. Sorry, but in Moose you don't have that form of access control. Without accessors, the car won't be able to change the odometer either. Either you have methods to change the value or you don't.
package Car;
use Moose;
has odometer => ( is => 'ro' );
sub drive {
my ($self, $distance) = @_;
...can't update odometer...
}
1;
| [reply] [d/l] |
| [reply] |