Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Moose "immutabilize" Best Practice

by Haarg (Curate)
on Dec 21, 2020 at 09:31 UTC ( #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 (Bishop) 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? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2021-10-18 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (73 votes). Check out past polls.

    Notices?