namespace::autoclean - Keep imports out of your namespace
version 0.04
package Foo; use namespace::autoclean; use Some::Package qw/imported_function/; sub bar { imported_function('stuff') } # later on: Foo->bar; # works Foo->imported_function; # will fail. imported_function got cleaned after compilation
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.
namespace::autoclean
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 pagma. It will also not touch anything that looks like a method, according to Class::MOP::Class::get_method_list.
use
Class::MOP::Class::get_method_list
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:
-also
use namespace::autoclean -also => ['some_function', 'another_function'];
If only one function needs to be additionally cleaned the -also switch also accepts a plain string:
use namespace::autoclean -also => 'some_function';
Florian Ragwitz <rafl@debian.org>
This software is copyright (c) 2009 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as perl itself.
namespace::clean
Class::MOP
B::Hooks::EndOfScope
To install namespace::autoclean, copy and paste the appropriate command in to your terminal.
cpanm
cpanm namespace::autoclean
CPAN shell
perl -MCPAN -e shell install namespace::autoclean
For more information on module installation, please visit the detailed CPAN module installation guide.