Moose::Manual::BestPractices shows the following example in the "namespace::autoclean and immutabilize" section:

package Person; use Moose; use namespace::autoclean; # extends, roles, attributes, etc. # methods __PACKAGE__->meta->make_immutable; 1;

Some discussion follows which includes: "This is preferred to placing no Moose at the end of your package".

I'm currently working through some rather old code (maybe 8-10 years old) which I haven't used in about 5 years. One module was working fine and still does — it didn't need much attention — and I mainly just tidied up the documentation and added some tests. After testing, I installed the new version and thought that was it.

Today, while working on another module of similar vintage, I happened upon the Moose::Manual::BestPractices document. What I read didn't seem to gel with what I remembered from the code I'd put to bed a day or two ago. It looks more like this:

package Person; use Moose; use X; use Y; extends 'Z'; use namespace::autoclean; # roles, attributes, etc. # methods no Z; no Y; no X; no Moose; __PACKAGE__->meta->make_immutable; 1;

I'm reasonably certain I probably would have followed some sort of best practice advice when I wrote that code; although, I really don't remember where that advice might have come from. I'm also aware that best practices change over time: perhaps what was good for Moose in 2010 is less good in 2020.

I'm interested in people's thoughts and opinions on this. What goes on behind the scenes with things like make_immutable is something of a black box to me: information such as "... allows Moose to speed up a lot of things ..." doesn't really help much. I'd like to find out more about this. Pointers to other documentation (instead of writing lengthy posts) are more than welcome.

Thanks in advance.

— Ken


In reply to Moose "immutabilize" Best Practice by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.