{
    "content": [
        {
            "type": "text",
            "text": "# namespace::clean (perldoc)\n\n## NAME\n\nnamespace::clean - Keep imports and functions out of your namespace\n\n## SYNOPSIS\n\npackage Foo;\nuse warnings;\nuse strict;\nuse Carp qw(croak);   # 'croak' will be removed\nsub bar { 23 }        # 'bar' will be removed\n# remove all previously defined functions\nuse namespace::clean;\nsub baz { bar() }     # 'baz' still defined, 'bar' still bound\n# begin to collection function names from here again\nno namespace::clean;\nsub quux { baz() }    # 'quux' will be removed\n# remove all functions defined after the 'no' unimport\nuse namespace::clean;\n# Will print: 'No', 'No', 'Yes' and 'No'\nprint +(PACKAGE->can('croak') ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('bar')   ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('baz')   ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('quux')  ? 'Yes' : 'No'), \"\\n\";\n1;\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (4 subsections)\n- **METHODS**\n- **IMPLEMENTATION DETAILS**\n- **SEE ALSO**\n- **THANKS**\n- **AUTHORS**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "namespace::clean",
        "section": "",
        "mode": "perldoc",
        "summary": "namespace::clean - Keep imports and functions out of your namespace",
        "synopsis": "package Foo;\nuse warnings;\nuse strict;\nuse Carp qw(croak);   # 'croak' will be removed\nsub bar { 23 }        # 'bar' will be removed\n# remove all previously defined functions\nuse namespace::clean;\nsub baz { bar() }     # 'baz' still defined, 'bar' still bound\n# begin to collection function names from here again\nno namespace::clean;\nsub quux { baz() }    # 'quux' will be removed\n# remove all functions defined after the 'no' unimport\nuse namespace::clean;\n# Will print: 'No', 'No', 'Yes' and 'No'\nprint +(PACKAGE->can('croak') ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('bar')   ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('baz')   ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('quux')  ? 'Yes' : 'No'), \"\\n\";\n1;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 29,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Keeping packages clean",
                        "lines": 43
                    },
                    {
                        "name": "Explicitly removing functions when your scope is compiled",
                        "lines": 18
                    },
                    {
                        "name": "Moose",
                        "lines": 10
                    },
                    {
                        "name": "Cleaning other packages",
                        "lines": 18
                    }
                ]
            },
            {
                "name": "METHODS",
                "lines": 29,
                "subsections": []
            },
            {
                "name": "IMPLEMENTATION DETAILS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "THANKS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "namespace::clean - Keep imports and functions out of your namespace\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "package Foo;\nuse warnings;\nuse strict;\n\nuse Carp qw(croak);   # 'croak' will be removed\n\nsub bar { 23 }        # 'bar' will be removed\n\n# remove all previously defined functions\nuse namespace::clean;\n\nsub baz { bar() }     # 'baz' still defined, 'bar' still bound\n\n# begin to collection function names from here again\nno namespace::clean;\n\nsub quux { baz() }    # 'quux' will be removed\n\n# remove all functions defined after the 'no' unimport\nuse namespace::clean;\n\n# Will print: 'No', 'No', 'Yes' and 'No'\nprint +(PACKAGE->can('croak') ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('bar')   ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('baz')   ? 'Yes' : 'No'), \"\\n\";\nprint +(PACKAGE->can('quux')  ? 'Yes' : 'No'), \"\\n\";\n\n1;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "",
                "subsections": [
                    {
                        "name": "Keeping packages clean",
                        "content": "When you define a function, or import one, into a Perl package, it will naturally also be\navailable as a method. This does not per se cause problems, but it can complicate subclassing\nand, for example, plugin classes that are included via multiple inheritance by loading them as\nbase classes.\n\nThe \"namespace::clean\" pragma will remove all previously declared or imported symbols at the end\nof the current package's compile cycle. Functions called in the package itself will still be\nbound by their name, but they won't show up as methods on your class or instances.\n\nBy unimporting via \"no\" you can tell \"namespace::clean\" to start collecting functions for the\nnext \"use namespace::clean;\" specification.\n\nYou can use the \"-except\" flag to tell \"namespace::clean\" that you don't want it to remove a\ncertain function or method. A common use would be a module exporting an \"import\" method along\nwith some functions:\n\nuse ModuleExportingImport;\nuse namespace::clean -except => [qw( import )];\n\nIf you just want to \"-except\" a single sub, you can pass it directly. For more than one value\nyou have to use an array reference.\n\nLate binding caveat\nNote that the technique used by this module relies on perl having resolved all names to actual\ncode references during the compilation of a scope. While this is almost always what the\ninterpreter does, there are some exceptions, notably the sort SUBNAME style of the \"sort\"\nbuilt-in invocation. The following example will not work, because \"sort\" does not try to resolve\nthe function name to an actual code reference until runtime.\n\nuse MyApp::Utils 'mysorter';\nuse namespace::clean;\n\nmy @sorted = sort mysorter @list;\n\nYou need to work around this by forcing a compile-time resolution like so:\n\nuse MyApp::Utils 'mysorter';\nuse namespace::clean;\n\nmy $mysortercref = \\&mysorter;\n\nmy @sorted = sort $mysortercref @list;\n"
                    },
                    {
                        "name": "Explicitly removing functions when your scope is compiled",
                        "content": "It is also possible to explicitly tell \"namespace::clean\" what packages to remove when the\nsurrounding scope has finished compiling. Here is an example:\n\npackage Foo;\nuse strict;\n\n# blessed NOT available\n\nsub myclass {\nuse Scalar::Util qw( blessed );\nuse namespace::clean qw( blessed );\n\n# blessed available\nreturn blessed shift;\n}\n\n# blessed NOT available\n"
                    },
                    {
                        "name": "Moose",
                        "content": "When using \"namespace::clean\" together with Moose you want to keep the installed \"meta\" method.\nSo your classes should look like:\n\npackage Foo;\nuse Moose;\nuse namespace::clean -except => 'meta';\n...\n\nSame goes for Moose::Role.\n"
                    },
                    {
                        "name": "Cleaning other packages",
                        "content": "You can tell \"namespace::clean\" that you want to clean up another package instead of the one\nimporting. To do this you have to pass in the \"-cleanee\" option like this:\n\npackage My::MooseX::namespace::clean;\nuse strict;\n\nuse namespace::clean (); # no cleanup, just load\n\nsub import {\nnamespace::clean->import(\n-cleanee => scalar(caller),\n-except  => 'meta',\n);\n}\n\nIf you don't care about \"namespace::clean\"s discover-and-\"-except\" logic, and just want to\nremove subroutines, try \"cleansubroutines\".\n"
                    }
                ]
            },
            "METHODS": {
                "content": "cleansubroutines\nThis exposes the actual subroutine-removal logic.\n\nnamespace::clean->cleansubroutines($cleanee, qw( subA subB ));\n\nwill remove \"subA\" and \"subB\" from $cleanee. Note that this will remove the subroutines\nimmediately and not wait for scope end. If you want to have this effect at a specific time (e.g.\n\"namespace::clean\" acts on scope compile end) it is your responsibility to make sure it runs at\nthat time.\n\nimport\nMakes a snapshot of the current defined functions and installs a B::Hooks::EndOfScope hook in\nthe current scope to invoke the cleanups.\n\nunimport\nThis method will be called when you do a\n\nno namespace::clean;\n\nIt will start a new section of code that defines functions to clean up.\n\ngetclassstore\nThis returns a reference to a hash in a passed package containing information about function\nnames included and excluded from removal.\n\ngetfunctions\nTakes a class as argument and returns all currently defined functions in it as a hash reference\nwith the function name as key and a typeglob reference to the symbol as value.\n",
                "subsections": []
            },
            "IMPLEMENTATION DETAILS": {
                "content": "This module works through the effect that a\n\ndelete $SomePackage::{foo};\n\nwill remove the \"foo\" symbol from $SomePackage for run time lookups (e.g., method calls) but\nwill leave the entry alive to be called by already resolved names in the package itself.\n\"namespace::clean\" will restore and therefor in effect keep all glob slots that aren't \"CODE\".\n\nA test file has been added to the perl core to ensure that this behaviour will be stable in\nfuture releases.\n\nJust for completeness sake, if you want to remove the symbol completely, use \"undef\" instead.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "B::Hooks::EndOfScope\n",
                "subsections": []
            },
            "THANKS": {
                "content": "Many thanks to Matt S Trout for the inspiration on the whole idea.\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "*   Robert 'phaylon' Sedlacek <rs@474.at>\n\n*   Florian Ragwitz <rafl@debian.org>\n\n*   Jesse Luehrs <doy@tozt.net>\n\n*   Peter Rabbitson <ribasushi@cpan.org>\n\n*   Father Chrysostomos <sprout@cpan.org>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "This software is copyright (c) 2011 by \"AUTHORS\"\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": []
            }
        }
    }
}