Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Making 'all' the attributes read only by default (Moo)

by blindluke (Hermit)
on Jan 23, 2015 at 12:05 UTC ( [id://1114271]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Making 'all' the attributes read only by default (Moo)
in thread Making 'all' the attributes read only by default (Moo)

There are some really good explanations in the blog post link I have provided. A simple answer is that if the attribute value is a reference, you can easily use the reference to change the object. Consider a Person object that has some friends, with friends being an array reference. You can make the friends attribute 'ro', but you gan still read the reference and use it to change the object, like this:

push @{ $john->friends }, $new_friend;

That is why I'm asking for a shortcut to writing is => 'ro', and not for a way to make the object immutable. I don't think that making the object truly immutable is a sensible goal. Making all the attributes readonly (in the way Moo understands it), on the other hand, can be useful.

- Luke

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114271]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2025-12-14 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (94 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.