{
    "mode": "perldoc",
    "parameter": "namespace::autoclean",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/namespace%3A%3Aautoclean/json",
    "generated": "2026-06-11T23:49:36Z",
    "synopsis": "package Foo;\nuse namespace::autoclean;\nuse Some::Package qw/importedfunction/;\nsub bar { importedfunction('stuff') }\n# later on:\nFoo->bar;               # works\nFoo->importedfunction; # will fail. importedfunction got cleaned after compilation",
    "sections": {
        "NAME": {
            "content": "namespace::autoclean - Keep imports out of your namespace\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 0.29\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package Foo;\nuse namespace::autoclean;\nuse Some::Package qw/importedfunction/;\n\nsub bar { importedfunction('stuff') }\n\n# later on:\nFoo->bar;               # works\nFoo->importedfunction; # will fail. importedfunction got cleaned after compilation\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "When you import a function into a Perl package, it will naturally also be available as a method.\n\nThe \"namespace::autoclean\" pragma will remove all imported symbols at the end of the current\npackage's compile cycle. Functions called in the package itself will still be bound by their\nname, but they won't show up as methods on your class or instances.\n\nThis module is very similar to namespace::clean, except it will clean all imported functions, no\nmatter if you imported them before or after you \"use\"d the pragma. It will also not touch\nanything that looks like a method.\n\nIf you're writing an exporter and you want to clean up after yourself (and your peers), you can\nuse the \"-cleanee\" switch to specify what package to clean:\n\npackage My::MooseX::namespace::autoclean;\nuse strict;\n\nuse namespace::autoclean (); # no cleanup, just load\n\nsub import {\nnamespace::autoclean->import(\n-cleanee => scalar(caller),\n);\n}\n\nWHAT IS AND ISN'T CLEANED\n\"namespace::autoclean\" will leave behind anything that it deems a method. For Moose classes,\nthis the based on the \"getmethodlist\" method on from the Class::MOP::Class. For non-Moose\nclasses, anything defined within the package will be identified as a method. This should match\nMoose's definition of a method. Additionally, the magic subs installed by overload will not be\ncleaned.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "-also => [ ITEM | REGEX | SUB, .. ]\n-also => ITEM\n-also => REGEX\n-also => SUB\nSometimes you don't want to clean imports only, but also helper functions you're using in your\nmethods. The \"-also\" switch can be used to declare a list of functions that should be removed\nadditional to any imports:\n\nuse namespace::autoclean -also => ['somefunction', 'anotherfunction'];\n\nIf only one function needs to be additionally cleaned the \"-also\" switch also accepts a plain\nstring:\n\nuse namespace::autoclean -also => 'somefunction';\n\nIn some situations, you may wish for a more *powerful* cleaning solution.\n\nThe \"-also\" switch can take a Regex or a CodeRef to match against local function names to clean.\n\nuse namespace::autoclean -also => qr/^/\n\nuse namespace::autoclean -also => sub { $ =~ m{^} };\n\nuse namespace::autoclean -also => [qr/^/ , qr/^hidden/ ];\n\nuse namespace::autoclean -also => [sub { $ =~ m/^/ or $ =~ m/^hidden/ }, sub { uc($) == $ } ];\n\n-except => [ ITEM | REGEX | SUB, .. ]\n-except => ITEM\n-except => REGEX\n-except => SUB\nThis takes exactly the same options as \"-also\" except that anything this matches will *not* be\ncleaned.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "When used with Moo classes, the heuristic used to check for methods won't work correctly for\nmethods from roles consumed at compile time.\n\npackage My::Class;\nuse Moo;\nuse namespace::autoclean;\n\n# Bad, any consumed methods will be cleaned\nBEGIN { with 'Some::Role' }\n\n# Good, methods from role will be maintained\nwith 'Some::Role';\n\nAdditionally, method detection may not work properly in Mouse classes in perls earlier than\n5.10.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   namespace::clean\n\n*   B::Hooks::EndOfScope\n\n*   namespace::sweep\n\n*   Sub::Exporter::ForMethods\n\n*   Sub::Name\n\n*   Sub::Install\n\n*   Test::CleanNamespaces\n\n*   Dist::Zilla::Plugin::Test::CleanNamespaces\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs may be submitted through the RT bug tracker\n<https://rt.cpan.org/Public/Dist/Display.html?Name=namespace-autoclean> (or\nbug-namespace-autoclean@rt.cpan.org <mailto:bug-namespace-autoclean@rt.cpan.org>).\n\nThere is also a mailing list available for users of this distribution, at\n<http://lists.perl.org/list/moose.html>.\n\nThere is also an irc channel available for users of this distribution, at \"#moose\" on\n\"irc.perl.org\" <irc://irc.perl.org/#moose>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Florian Ragwitz <rafl@debian.org>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Karen Etheridge <ether@cpan.org>\n\n*   Graham Knop <haarg@haarg.org>\n\n*   Dave Rolsky <autarch@urth.org>\n\n*   Kent Fredric <kentfredric@gmail.com>\n\n*   Tomas Doran <bobtfish@bobtfish.net>\n\n*   Shawn M Moore <cpan@sartak.org>\n\n*   Felix Ostmann <sadrak@cpan.org>\n\n*   Chris Prather <chris@prather.org>\n\n*   Andrew Rodland <arodland@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2009 by Florian Ragwitz.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "namespace::autoclean - Keep imports out of your namespace",
    "flags": [],
    "examples": [],
    "see_also": []
}