{
    "content": [
        {
            "type": "text",
            "text": "# SelfLoader (man)\n\n## NAME\n\nSelfLoader - load functions only on demand\n\n## SYNOPSIS\n\npackage FOOBAR;\nuse SelfLoader;\n... (initializing code)\nDATA\nsub {....\n\n## DESCRIPTION\n\nThis module tells its users that functions in the FOOBAR package are to be autoloaded from\nafter the \"DATA\" token.  See also \"Autoloading\" in perlsub.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (5 subsections)\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "SelfLoader",
        "section": "",
        "mode": "man",
        "summary": "SelfLoader - load functions only on demand",
        "synopsis": "package FOOBAR;\nuse SelfLoader;\n... (initializing code)\nDATA\nsub {....",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 19,
                "subsections": [
                    {
                        "name": "SelfLoader autoloading",
                        "lines": 20
                    },
                    {
                        "name": "Autoloading and package lexicals",
                        "lines": 10
                    },
                    {
                        "name": "SelfLoader and AutoLoader",
                        "lines": 42
                    },
                    {
                        "name": "Classes and inherited methods.",
                        "lines": 21
                    },
                    {
                        "name": "Multiple packages and fully qualified subroutine names",
                        "lines": 17
                    }
                ]
            },
            {
                "name": "AUTHOR",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 50,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "SelfLoader - load functions only on demand\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "package FOOBAR;\nuse SelfLoader;\n\n... (initializing code)\n\nDATA\nsub {....\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module tells its users that functions in the FOOBAR package are to be autoloaded from\nafter the \"DATA\" token.  See also \"Autoloading\" in perlsub.\n\nThe DATA token\nThe \"DATA\" token tells the perl compiler that the perl code for compilation is finished.\nEverything after the \"DATA\" token is available for reading via the filehandle\nFOOBAR::DATA, where FOOBAR is the name of the current package when the \"DATA\" token is\nreached. This works just the same as \"END\" does in package 'main', but for other modules\ndata after \"END\" is not automatically retrievable, whereas data after \"DATA\" is.  The\n\"DATA\" token is not recognized in versions of perl prior to 5.001m.\n\nNote that it is possible to have \"DATA\" tokens in the same package in multiple files, and\nthat the last \"DATA\" token in a given package that is encountered by the compiler is the\none accessible by the filehandle. This also applies to \"END\" and main, i.e. if the 'main'\nprogram has an \"END\", but a module 'require'd (not 'use'd) by that program has a\n'package main;' declaration followed by an '\"DATA\"', then the \"DATA\" filehandle is set to\naccess the data after the \"DATA\" in the module, not the data after the \"END\" token\nin the 'main' program, since the compiler encounters the 'require'd file later.\n",
                "subsections": [
                    {
                        "name": "SelfLoader autoloading",
                        "content": "The SelfLoader works by the user placing the \"DATA\" token after perl code which needs to\nbe compiled and run at 'require' time, but before subroutine declarations that can be loaded\nin later - usually because they may never be called.\n\nThe SelfLoader will read from the FOOBAR::DATA filehandle to load in the data after\n\"DATA\", and load in any subroutine when it is called. The costs are the one-time parsing\nof the data after \"DATA\", and a load delay for the first call of any autoloaded\nfunction. The benefits (hopefully) are a speeded up compilation phase, with no need to load\nfunctions which are never used.\n\nThe SelfLoader will stop reading from \"DATA\" if it encounters the \"END\" token - just\nas you would expect.  If the \"END\" token is present, and is followed by the token DATA,\nthen the SelfLoader leaves the FOOBAR::DATA filehandle open on the line after that token.\n\nThe SelfLoader exports the \"AUTOLOAD\" subroutine to the package using the SelfLoader, and\nthis loads the called subroutine when it is first called.\n\nThere is no advantage to putting subroutines which will always be called after the\n\"DATA\" token.\n"
                    },
                    {
                        "name": "Autoloading and package lexicals",
                        "content": "A 'my $packlexical' statement makes the variable $packlexical local only to the file up\nto the \"DATA\" token. Subroutines declared elsewhere cannot see these types of\nvariables, just as if you declared subroutines in the package but in another file, they\ncannot see these variables.\n\nSo specifically, autoloaded functions cannot see package lexicals (this applies to both the\nSelfLoader and the Autoloader).  The \"vars\" pragma provides an alternative to defining\npackage-level globals that will be visible to autoloaded routines. See the documentation on\nvars in the pragma section of perlmod.\n"
                    },
                    {
                        "name": "SelfLoader and AutoLoader",
                        "content": "The SelfLoader can replace the AutoLoader - just change 'use AutoLoader' to 'use SelfLoader'\n(though note that the SelfLoader exports the AUTOLOAD function - but if you have your own\nAUTOLOAD and are using the AutoLoader too, you probably know what you're doing), and the\n\"END\" token to \"DATA\". You will need perl version 5.001m or later to use this\n(version 5.001 with all patches up to patch m).\n\nThere is no need to inherit from the SelfLoader.\n\nThe SelfLoader works similarly to the AutoLoader, but picks up the subs from after the\n\"DATA\" instead of in the 'lib/auto' directory.  There is a maintenance gain in not\nneeding to run AutoSplit on the module at installation, and a runtime gain in not needing to\nkeep opening and closing files to load subs. There is a runtime loss in needing to parse the\ncode after the \"DATA\". Details of the AutoLoader and another view of these distinctions\ncan be found in that module's documentation.\n\nDATA, END, and the FOOBAR::DATA filehandle.\nThis section is only relevant if you want to use the \"FOOBAR::DATA\" together with the\nSelfLoader.\n\nData after the \"DATA\" token in a module is read using the FOOBAR::DATA filehandle.\n\"END\" can still be used to denote the end of the \"DATA\" section if followed by the\ntoken DATA - this is supported by the SelfLoader. The \"FOOBAR::DATA\" filehandle is left open\nif an \"END\" followed by a DATA is found, with the filehandle positioned at the start of\nthe line after the \"END\" token. If no \"END\" token is present, or an \"END\" token\nwith no DATA token on the same line, then the filehandle is closed.\n\nThe SelfLoader reads from wherever the current position of the \"FOOBAR::DATA\" filehandle is,\nuntil the EOF or \"END\". This means that if you want to use that filehandle (and ONLY if\nyou want to), you should either\n\n1. Put all your subroutine declarations immediately after the \"DATA\" token and put your\nown data after those declarations, using the \"END\" token to mark the end of subroutine\ndeclarations. You must also ensure that the SelfLoader reads first by  calling\n'SelfLoader->loadstubs();', or by using a function which is selfloaded;\n\nor\n\n2. You should read the \"FOOBAR::DATA\" filehandle first, leaving the handle open and\npositioned at the first line of subroutine declarations.\n\nYou could conceivably do both.\n"
                    },
                    {
                        "name": "Classes and inherited methods.",
                        "content": "For modules which are not classes, this section is not relevant.  This section is only\nrelevant if you have methods which could be inherited.\n\nA subroutine stub (or forward declaration) looks like\n\nsub stub;\n\ni.e. it is a subroutine declaration without the body of the subroutine. For modules which are\nnot classes, there is no real need for stubs as far as autoloading is concerned.\n\nFor modules which ARE classes, and need to handle inherited methods, stubs are needed to\nensure that the method inheritance mechanism works properly. You can load the stubs into the\nmodule at 'require' time, by adding the statement 'SelfLoader->loadstubs();' to the module\nto do this.\n\nThe alternative is to put the stubs in before the \"DATA\" token BEFORE releasing the\nmodule, and for this purpose the \"Devel::SelfStubber\" module is available.  However this does\nrequire the extra step of ensuring that the stubs are in the module. If this is done I\nstrongly recommend that this is done BEFORE releasing the module - it should NOT be done at\ninstall time in general.\n"
                    },
                    {
                        "name": "Multiple packages and fully qualified subroutine names",
                        "content": "Subroutines in multiple packages within the same file are supported - but you should note\nthat this requires exporting the \"SelfLoader::AUTOLOAD\" to every package which requires it.\nThis is done automatically by the SelfLoader when it first loads the subs into the cache, but\nyou should really specify it in the initialization before the \"DATA\" by putting a 'use\nSelfLoader' statement in each package.\n\nFully qualified subroutine names are also supported. For example,\n\nDATA\nsub foo::bar {23}\npackage baz;\nsub dob {32}\n\nwill all be loaded correctly by the SelfLoader, and the SelfLoader will ensure that the\npackages 'foo' and 'baz' correctly have the SelfLoader \"AUTOLOAD\" method when the data after\n\"DATA\" is first parsed.\n"
                    }
                ]
            },
            "AUTHOR": {
                "content": "\"SelfLoader\" is maintained by the perl5-porters. Please direct any questions to the canonical\nmailing list. Anything that is applicable to the CPAN release can be sent to its maintainer,\nthough.\n\nAuthor and Maintainer: The Perl5-Porters <perl5-porters@perl.org>\n\nMaintainer of the CPAN release: Steffen Mueller <smueller@cpan.org>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "This package has been part of the perl core since the first release of perl5. It has been\nreleased separately to CPAN so older installations can benefit from bug fixes.\n\nThis package has the same copyright and license as the perl core:\n\nCopyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,\n2006 by Larry Wall and others\n\nAll rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the terms of\neither:\n\na)  the GNU General Public License as published by the Free Software Foundation; either\nversion 1, or (at your option) any later version, or\n\nb)  the \"Artistic License\" which comes with this Kit.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;\nwithout even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee either the GNU General Public License or the Artistic License for more details.\n\nYou should have received a copy of the Artistic License with this Kit, in the file named\n\"Artistic\".  If not, I'll be glad to provide one.\n\nYou should also have received a copy of the GNU General Public License along with this\nprogram in the file named \"Copying\". If not, write to the Free Software Foundation, Inc., 51\nFranklin St, Fifth Floor, Boston, MA 02110-1301, USA or visit their web page on the internet\nat <http://www.gnu.org/copyleft/gpl.html>.\n\nFor those of you that choose to use the GNU General Public License, my interpretation of the\nGNU General Public License is that no Perl script falls under the terms of the GPL unless you\nexplicitly put said script under the terms of the GPL yourself.  Furthermore, any object code\nlinked with perl does not automatically fall under the terms of the GPL, provided such object\ncode only adds definitions of subroutines and variables, and does not otherwise impair the\nresulting interpreter from executing any standard Perl script.  I consider linking in C\nsubroutines in this manner to be the moral equivalent of defining subroutines in the Perl\nlanguage itself.  You may sell such an object file as proprietary provided that you provide\nor offer to provide the Perl source, as specified by the GNU General Public License.  (This\nis merely an alternate way of specifying input to the program.)  You may also sell a binary\nproduced by the dumping of a running Perl script that belongs to you, provided that you\nprovide or offer to provide the Perl source as specified by the GPL.  (The fact that a Perl\ninterpreter and your code are in the same binary file is, in this case, a form of mere\naggregation.)  This is my interpretation of the GPL.  If you still have concerns or\ndifficulties understanding my intent, feel free to contact me.  Of course, the Artistic\nLicense spells all this out for your protection, so you may prefer to use that.\n\n\n\nperl v5.34.0                                 2025-07-25                            SelfLoader(3perl)",
                "subsections": []
            }
        }
    }
}