{
    "mode": "perldoc",
    "parameter": "Sub::Util",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Sub%3A%3AUtil/json",
    "generated": "2026-06-12T11:59:42Z",
    "synopsis": "use Sub::Util qw( prototype setprototype subname setsubname );",
    "sections": {
        "NAME": {
            "content": "Sub::Util - A selection of utility subroutines for subs and CODE references\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 for operating on subs\nand CODE references.\n\nThe rationale for inclusion in this module is that the function performs some work for which an\nXS implementation is essential because it cannot be implemented in Pure Perl, and which is\nsufficiently-widely used across CPAN that its popularity warrants inclusion in a core module,\nwhich this is.\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "prototype\nmy $proto = prototype( $code )\n\n*Since version 1.40.*\n\nReturns the prototype of the given $code reference, if it has one, as a string. This is the same\nas the \"CORE::prototype\" operator; it is included here simply for symmetry and completeness with\nthe other functions.\n\nsetprototype\nmy $code = setprototype $prototype, $code;\n\n*Since version 1.40.*\n\nSets the prototype of the function given by the $code reference, or deletes it if $prototype is\n\"undef\". Returns the $code reference itself.\n\n*Caution*: This function takes arguments in a different order to the previous copy of the code\nfrom \"Scalar::Util\". This is to match the order of \"setsubname\", and other potential additions\nin this file. This order has been chosen as it allows a neat and simple chaining of other\n\"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\n*Since version 1.40.*\n\nReturns the name of the given $code reference, if it has one. Normal named subs will give a\nfully-qualified name consisting of the package and the localname separated by \"::\". Anonymous\ncode references will give \"ANON\" as the localname. If the package the code was compiled in\nhas been deleted (e.g. using \"deletepackage\" from Symbol), \"ANON\" will be returned as the\npackage name. If a name has been set using \"setsubname\", this name will be returned instead.\n\nThis function was inspired by \"subfullname\" from Sub::Identify. The remaining functions that\n\"Sub::Identify\" implements can easily be emulated 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\n*Users of Sub::Name beware*: This function is not the same as \"Sub::Name::subname\"; it returns\nthe existing name of the sub rather than changing it. To set or change a name, see instead\n\"setsubname\".\n\nsetsubname\nmy $code = setsubname $name, $code;\n\n*Since version 1.40.*\n\nSets the name of the function given by the $code reference. Returns the $code reference itself.\nIf the $name is unqualified, the package of the caller is used to qualify it.\n\nThis is useful for applying names to anonymous CODE references so that stack traces and similar\nsituations, to give a useful name rather than having the default of \"ANON\". Note that this\nname is only used for this 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 of \"caller\", for stack\ntraces or similar, there is no actual requirement that the name be syntactically valid as a perl\nfunction name. This could be used to attach extra information that could be useful in debugging\nstack traces.\n\nThis function was copied from \"Sub::Name::subname\" and renamed to the naming convention of this\nmodule.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "The general structure of this module was written by Paul Evans <leonerd@leonerd.org.uk>.\n\nThe XS implementation of \"setsubname\" was copied from Sub::Name by Matthijs van Duin\n<xmath@cpan.org>\n",
            "subsections": []
        }
    },
    "summary": "Sub::Util - A selection of utility subroutines for subs and CODE references",
    "flags": [],
    "examples": [],
    "see_also": []
}