Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Moose "immutabilize" Best Practice

by Haarg (Priest)
on Dec 21, 2020 at 09:31 UTC ( [id://11125521]=note: print w/replies, xml ) Need Help??


in reply to Moose "immutabilize" Best Practice

The main thing make_immutable does is generate an optimized constructor for your class. You have to do this manually, because Moose doesn't know when you are done defining the class. Rather than going through all of the class metadata during construction, the optimized constructor is built to handle the specific attributes defined in your class.

namespace::autoclean and no Moose; are doing similar things. They remove imported functions in your class so that they can't be used as methods. This includes things like extends and has. But namespace::autoclean will automatically clean all of the imported functions, so it is much easier to use. Rather than no X; no Y;, a single use namespace::autoclean; will take care of all of the imports. It will also clean functions from modules that don't provide an unimport method to remove functions.

Replies are listed 'Best First'.
Re^2: Moose "immutabilize" Best Practice
by kcott (Archbishop) on Dec 21, 2020 at 11:10 UTC

    G'day Haarg,

    ++ Thankyou very much. That was exactly the sort of information I was looking for.

    My understanding of make_immutable, namespace::autoclean and no Moose was very blurry; particularly with respect to how, and to what extent, they interoperated. Your excellent post has cleared that up for me. Thanks again.

    — Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-25 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found