Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

perl

moose

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.

like image 238
Sérgio Bernardino Avatar asked Mar 04 '12 21:03

Sérgio Bernardino


1 Answers

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.

like image 75
cjm Avatar answered Nov 15 '22 09:11

cjm