Why is "use namespace::autoclean" preferred to "no Moose"?
Asked Answered
A

1

16

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, including Moose keywords. Once the class has been built, these keywords are not needed. (This is preferred to placing no 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.

Alsacelorraine answered 4/3, 2012 at 21:41 Comment(0)
D
18

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.

Dehumidifier answered 4/3, 2012 at 21:53 Comment(2)
namespace::autoclean will also break your code if you're planning on using overloads at the same time. For that case you may want to try out namespace::sweep.Photoconduction
Current namespace::autoclean (v0.28, Oct 2015) documentation states that "the magic subs installed by overload will not be cleaned".Kandi

© 2022 - 2024 — McMap. All rights reserved.