in reply to Re^2: Psychic Disconnect and Object Systems
in thread Psychic Disconnect and Object Systems

hum? My odometer changes all the time. You wouldn't use is => 'ro' for a car's mileage cause you wouldn't be able to change it as the car moves.

Replies are listed 'Best First'.
Re^4: Psychic Disconnect and Object Systems
by JavaFan (Canon) on Apr 18, 2011 at 22:40 UTC
    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.

      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;
        Djees, then don't use Moose. Claiming odometers need setters because otherwise it cannot be implemented in Moose is just a reason to not use Moose. The AM came with the example of the odometer as "real world example of a read-only variable that cannot be recalculated".

        I don't think Detroit will start equiping odometers with knobs to set the value just because Moose cannot simulate it.