DESCRIPTION

When you import a function into a Perl package, it will naturally also be available as a method.

The namespace::autoclean pragma will remove all imported symbols at the end of the current package's compile cycle. Functions called in the package itself will still be bound by their name, but they won't show up as methods on your class or instances.

This module is very similar to namespace::clean, except it will clean all imported functions, no matter if you imported them before or after you used the pragma. It will also not touch anything that looks like a method.

If you're writing an exporter and you want to clean up after yourself (and your peers), you can use the -cleanee switch to specify what package to clean:

WHAT IS AND ISN'T CLEANED

namespace::autoclean will leave behind anything that it deems a method. For Moose classes, this the based on the get_method_list method on from the Class::MOP::Class. For non-Moose classes, anything defined within the package will be identified as a method. This should match Moose's definition of a method. Additionally, the magic subs installed by overload will not be cleaned.

PARAMETERS

-also => [ ITEM | REGEX | SUB, .. ]

-also => ITEM

-also => REGEX

-also => SUB

Sometimes you don't want to clean imports only, but also helper functions you're using in your methods. The -also switch can be used to declare a list of functions that should be removed additional to any imports:

usenamespace::autoclean-also=>['some_function','another_function'];

If only one function needs to be additionally cleaned the -also switch also accepts a plain string:

usenamespace::autoclean-also=>'some_function';

In some situations, you may wish for a more powerful cleaning solution.

The -also switch can take a Regex or a CodeRef to match against local function names to clean.