Writing to read-only attributes inside a Perl Moose class

后端 未结 3 878
别那么骄傲
别那么骄傲 2021-01-12 19:06

Using Perl and Moose, object data can be accessed in 2 ways.

$self->{attribute} or $self->attribute()

Here is a si

3条回答
  •  无人共我
    2021-01-12 19:40

    Out-of-the-box perl isn't type safe and doesn't have much in the way of encapsulation, so it's easy to do reckless things. Moose imposes some civilization on your perl object, exchanging security and stability for some liberty. If Moose gets too stifling, the underlying Perl is still there so there are ways to work around any laws the iron fist of Moose tries to lay down.

    Once you have wrapped your head around the fact that you have declared an attribute read-only, but you want to change it, even though you also said you wanted it to be read-only, and in most universes you declare something read only because you don't want to change it, then by all means go ahead and update $person->{age}. After all, you know what you are doing.

提交回复
热议问题