{
    "mode": "info",
    "parameter": "Sub::Util",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/Sub%3A%3AUtil/json",
    "generated": "2026-07-05T13:23:13Z",
    "synopsis": "use Sub::Util qw( prototype setprototype subname setsubname );",
    "sections": {
        "NAME": {
            "content": "Sub::Util - A selection of utility subroutines for subs and CODE\nreferences\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Sub::Util qw( prototype setprototype subname setsubname );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Sub::Util\" contains a selection of utility subroutines that are useful\nfor operating on subs and CODE references.\n\nThe rationale for inclusion in this module is that the function\nperforms some work for which an XS implementation is essential because\nit cannot be implemented in Pure Perl, and which is sufficiently-widely\nused across CPAN that its popularity warrants inclusion in a core\nmodule, which this is.\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "prototype\nmy $proto = prototype( $code )\n\nSince version 1.40.\n\nReturns the prototype of the given $code reference, if it has one, as a\nstring. This is the same as the \"CORE::prototype\" operator; it is\nincluded here simply for symmetry and completeness with the other\nfunctions.\n\nsetprototype\nmy $code = setprototype $prototype, $code;\n\nSince version 1.40.\n\nSets the prototype of the function given by the $code reference, or\ndeletes it if $prototype is \"undef\". Returns the $code reference\nitself.\n\nCaution: This function takes arguments in a different order to the\nprevious copy of the code from \"Scalar::Util\". This is to match the\norder of \"setsubname\", and other potential additions in this file.\nThis order has been chosen as it allows a neat and simple chaining of\nother \"Sub::Util::set*\" functions as might become available, such as:\n\nmy $code =\nsetsubname   namehere =>\nsetprototype '&@'      =>\nsetattribute ':lvalue' =>\nsub { ...... };\n\nsubname\nmy $name = subname( $code )\n\nSince version 1.40.\n\nReturns the name of the given $code reference, if it has one. Normal\nnamed subs will give a fully-qualified name consisting of the package\nand the localname separated by \"::\". Anonymous code references will\ngive \"ANON\" as the localname. If the package the code was compiled\nin has been deleted (e.g. using \"deletepackage\" from Symbol),\n\"ANON\" will be returned as the package name. If a name has been set\nusing \"setsubname\", this name will be returned instead.\n\nThis function was inspired by \"subfullname\" from Sub::Identify. The\nremaining functions that \"Sub::Identify\" implements can easily be\nemulated using regexp operations, such as\n\nsub getcodeinfo { return (subname $[0]) =~ m/^(.+)::(.*?)$/ }\nsub subname      { return (getcodeinfo $[0])[0] }\nsub stashname    { return (getcodeinfo $[0])[1] }\n\nUsers of Sub::Name beware: This function is not the same as\n\"Sub::Name::subname\"; it returns the existing name of the sub rather\nthan changing it. To set or change a name, see instead \"setsubname\".\n\nsetsubname\nmy $code = setsubname $name, $code;\n\nSince version 1.40.\n\nSets the name of the function given by the $code reference. Returns the\n$code reference itself. If the $name is unqualified, the package of the\ncaller is used to qualify it.\n\nThis is useful for applying names to anonymous CODE references so that\nstack traces and similar situations, to give a useful name rather than\nhaving the default of \"ANON\". Note that this name is only used for\nthis situation; the \"setsubname\" will not install it into the symbol\ntable; you will have to do that yourself if required.\n\nHowever, since the name is not used by perl except as the return value\nof \"caller\", for stack traces or similar, there is no actual\nrequirement that the name be syntactically valid as a perl function\nname. This could be used to attach extra information that could be\nuseful in debugging stack traces.\n\nThis function was copied from \"Sub::Name::subname\" and renamed to the\nnaming convention of this module.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "The general structure of this module was written by Paul Evans\n<leonerd@leonerd.org.uk>.\n\nThe XS implementation of \"setsubname\" was copied from Sub::Name by\nMatthijs van Duin <xmath@cpan.org>\n\nperl v5.34.0                      2026-06-23                  Sub::Util(3perl)",
            "subsections": []
        }
    },
    "summary": "Sub::Util - A selection of utility subroutines for subs and CODE references",
    "flags": [],
    "examples": [],
    "see_also": []
}