http://qs321.pair.com?node_id=11125521


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