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
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 "use"d 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:
package My::MooseX::namespace::autoclean; use strict; use namespace::autoclean (); # no cleanup, just load sub import { namespace::autoclean->import( -cleanee => scalar(caller), ); }
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';
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.
use namespace::autoclean -also => qr/^_/ use namespace::autoclean -also => sub { $_ =~ m{^_} }; use namespace::autoclean -also => [qr/^_/ , qr/^hidden_/ ]; use namespace::autoclean -also => [sub { $_ =~ m/^_/ or $_ =~ m/^hidden/ }, sub { uc($_) == $_ } ];
package My::Class; use Moo; use namespace::autoclean; # Bad, any consumed methods will be cleaned BEGIN { with 'Some::Role' } # Good, methods from role will be maintained with 'Some::Role';
Additionally, method detection may not work properly in Mouse classes in perls earlier than 5.10.
There is also a mailing list available for users of this distribution, at <http://lists.perl.org/list/moose.html>.
There is also an irc channel available for users of this distribution, at "#moose" on "irc.perl.org" <irc://irc.perl.org/#moose>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.