An often seen recommendation on best practices regarding Moose
is the following:
"The use
namespace::autoclean
bit is simply good code hygiene, as it removes imported symbols from your class's namespace at the end of your package's compile cycle, includingMoose
keywords. Once the class has been built, these keywords are not needed. (This is preferred to placingno Moose
at the end of your package)."
Taken for Moose::Manual::BestPractices (emphasis mine).
I understand everything regarding the quote above, except for one thing: why is the use of namespace::autoclean
preferred to the use of no Moose
at the end of the lexical scope?
Is it just because namespace::autoclean
is more versatile, allowing for more options in its use, or is there something intrinsic to the way it was implemented (specially tailored for Moose
classes, perhaps) that makes it more reliable?
I found no documentation clarifying this, and I would much like to know the right answer.
no Moose
gets rid of only those functions imported by use Moose
. use namespace::autoclean
gets rid of all imported functions.
If you always use namespace::autoclean
, then you don't have to remember to switch no Moose
to use namespace::autoclean
if you later come back and import a function from some module. Otherwise, you might forget to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With