{
    "mode": "perldoc",
    "parameter": "Sub::Quote",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Sub%3A%3AQuote/json",
    "generated": "2026-06-12T06:21:31Z",
    "synopsis": "package Silly;\nuse Sub::Quote qw(quotesub unquotesub quotedfromsub);\nquotesub 'Silly::kitty', q{ print \"meow\" };\nquotesub 'Silly::doggy', q{ print \"woof\" };\nmy $sound = 0;\nquotesub 'Silly::dagron',\nq{ print ++$sound % 2 ? 'burninate' : 'roar' },\n{ '$sound' => \\$sound };\nAnd elsewhere:\nSilly->kitty;  # meow\nSilly->doggy;  # woof\nSilly->dagron; # burninate\nSilly->dagron; # roar\nSilly->dagron; # burninate",
    "sections": {
        "NAME": {
            "content": "Sub::Quote - Efficient generation of subroutines via string eval\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package Silly;\n\nuse Sub::Quote qw(quotesub unquotesub quotedfromsub);\n\nquotesub 'Silly::kitty', q{ print \"meow\" };\n\nquotesub 'Silly::doggy', q{ print \"woof\" };\n\nmy $sound = 0;\n\nquotesub 'Silly::dagron',\nq{ print ++$sound % 2 ? 'burninate' : 'roar' },\n{ '$sound' => \\$sound };\n\nAnd elsewhere:\n\nSilly->kitty;  # meow\nSilly->doggy;  # woof\nSilly->dagron; # burninate\nSilly->dagron; # roar\nSilly->dagron; # burninate\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This package provides performant ways to generate subroutines from strings.\n",
            "subsections": []
        },
        "SUBROUTINES": {
            "content": "quotesub\nmy $coderef = quotesub 'Foo::bar', q{ print $x++ . \"\\n\" }, { '$x' => \\0 };\n\nArguments: ?$name, $code, ?\\%captures, ?\\%options\n\n$name is the subroutine where the coderef will be installed.\n\n$code is a string that will be turned into code.\n\n\"\\%captures\" is a hashref of variables that will be made available to the code. The keys should\nbe the full name of the variable to be made available, including the sigil. The values should be\nreferences to the values. The variables will contain copies of the values. See the \"SYNOPSIS\"'s\n\"Silly::dagron\" for an example using captures.\n\nExported by default.\n\noptions\n\"noinstall\"\nBoolean. Set this option to not install the generated coderef into the passed subroutine name\non undefer.\n\n\"nodefer\"\nBoolean. Prevents a Sub::Defer wrapper from being generated for the quoted sub. If the sub\nwill most likely be called at some point, setting this is a good idea. For a sub that will\nmost likely be inlined, it is not recommended.\n\n\"package\"\nThe package that the quoted sub will be evaluated in. If not specified, the package from sub\ncalling \"quotesub\" will be used.\n\n\"hints\"\nThe value of $^H to use for the code being evaluated. This captures the settings of the strict\npragma. If not specified, the value from the calling code will be used.\n\n\"warningbits\"\nThe value of \"${^WARNINGBITS}\" to use for the code being evaluated. This captures the\nwarnings set. If not specified, the warnings from the calling code will be used.\n\n\"%^H\"\nThe value of \"%^H\" to use for the code being evaluated. This captures additional pragma\nsettings. If not specified, the value from the calling code will be used if possible (on perl\n5.10+).\n\n\"attributes\"\nThe \"Subroutine Attributes\" in perlsub to apply to the sub generated. Should be specified as\nan array reference. The attributes will be applied to both the generated sub and the deferred\nwrapper, if one is used.\n\n\"file\"\nThe apparent filename to use for the code being evaluated.\n\n\"line\"\nThe apparent line number to use for the code being evaluated.\n\nunquotesub\nmy $coderef = unquotesub $sub;\n\nForcibly replace subroutine with actual code.\n\nIf $sub is not a quoted sub, this is a no-op.\n\nExported by default.\n\nquotedfromsub\nmy $data = quotedfromsub $sub;\n\nmy ($name, $code, $captures, $compiledsub) = @$data;\n\nReturns original arguments to quotesub, plus the compiled version if this sub has already been\nunquoted.\n\nNote that $sub can be either the original quoted version or the compiled version for\nconvenience.\n\nExported by default.\n\ninlinify\nmy $prelude = captureunroll '$captures', {\n'$x' => 1,\n'$y' => 2,\n}, 4;\n\nmy $inlinedcode = inlinify q{\nmy ($x, $y) = @;\n\nprint $x + $y . \"\\n\";\n}, '$x, $y', $prelude;\n\nTakes a string of code, a string of arguments, a string of code which acts as a \"prelude\", and a\nBoolean representing whether or not to localize the arguments.\n\nquotify\nmy $quotedvalue = quotify $value;\n\nQuotes a single (non-reference) scalar value for use in a code string. The result should\nreproduce the original value, including strings, undef, integers, and floating point numbers.\nThe resulting floating point numbers (including infinites and not a number) should be precisely\nequal to the original, if possible. The exact format of the resulting number should not be\nrelied on, as it may include hex floats or math expressions.\n\ncaptureunroll\nmy $prelude = captureunroll '$captures', {\n'$x' => 1,\n'$y' => 2,\n}, 4;\n\nArguments: $from, \\%captures, $indent\n\nGenerates a snippet of code which is suitable to be used as a prelude for \"inlinify\". $from is a\nstring will be used as a hashref in the resulting code. The keys of %captures are the names of\nthe variables and the values are ignored. $indent is the number of spaces to indent the result\nby.\n\nqsub\nmy $hash = {\ncoderef => qsub q{ print \"hello\"; },\nother   => 5,\n};\n\nArguments: $code\n\nWorks exactly like \"quotesub\", but includes a prototype to only accept a single parameter. This\nmakes it easier to include in hash structures or lists.\n\nExported by default.\n\nsanitizeidentifier\nmy $varname = '$variablefor' . sanitizeidentifier('@name');\nquotesub qq{ print \\$${varname} }, { $varname => \\$value };\n\nArguments: $identifier\n\nSanitizes a value so that it can be used in an identifier.\n",
            "subsections": []
        },
        "ENVIRONMENT": {
            "content": "SUBQUOTEDEBUG\nCauses code to be output to \"STDERR\" before being evaled. Several forms are supported:\n\n1   All subs will be output.\n\n\"/foo/\"\nSubs will be output if their code matches the given regular expression.\n\n\"simpleidentifier\"\nAny sub with the given name will be output.\n\n\"Full::identifier\"\nA sub matching the full name will be output.\n\n\"Package::Name::\"\nAny sub in the given package (including anonymous subs) will be output.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "Much of this is just string-based code-generation, and as a result, a few caveats apply.\n\nreturn\nCalling \"return\" from a quotesub'ed sub will not likely do what you intend. Instead of\nreturning from the code you defined in \"quotesub\", it will return from the overall function it\nis composited into.\n\nSo when you pass in:\n\nquotesub q{  return 1 if $condition; $morecode }\n\nIt might turn up in the intended context as follows:\n\nsub foo {\n\n<important code a>\ndo {\nreturn 1 if $condition;\n$morecode\n};\n<important code b>\n\n}\n\nWhich will obviously return from foo, when all you meant to do was return from the code context\nin quotesub and proceed with running important code b.\n\npragmas\n\"Sub::Quote\" preserves the environment of the code creating the quoted subs. This includes the\npackage, strict, warnings, and any other lexical pragmas. This is done by prefixing the code\nwith a block that sets up a matching environment. When inlining \"Sub::Quote\" subs, care should\nbe taken that user pragmas won't effect the rest of the code.\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Users' IRC: #moose on irc.perl.org\n\nDevelopment and contribution IRC: #web-simple on irc.perl.org\n\nBugtracker: <https://rt.cpan.org/Public/Dist/Display.html?Name=Sub-Quote>\n\nGit repository: <git://github.com/moose/Sub-Quote.git>\n\nGit browser: <https://github.com/moose/Sub-Quote>\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "frew - Arthur Axel \"fREW\" Schmidt (cpan:FREW) <frioux@gmail.com>\n\nribasushi - Peter Rabbitson (cpan:RIBASUSHI) <ribasushi@cpan.org>\n\nMithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>\n\ntobyink - Toby Inkster (cpan:TOBYINK) <tobyink@cpan.org>\n\nhaarg - Graham Knop (cpan:HAARG) <haarg@cpan.org>\n\nbluefeet - Aran Deltac (cpan:BLUEFEET) <bluefeet@gmail.com>\n\nether - Karen Etheridge (cpan:ETHER) <ether@cpan.org>\n\ndolmen - Olivier Mengué (cpan:DOLMEN) <dolmen@cpan.org>\n\nalexbio - Alessandro Ghedini (cpan:ALEXBIO) <alexbio@cpan.org>\n\ngetty - Torsten Raudssus (cpan:GETTY) <torsten@raudss.us>\n\narcanez - Justin Hunter (cpan:ARCANEZ) <justin.d.hunter@gmail.com>\n\nkanashiro - Lucas Kanashiro (cpan:KANASHIRO) <kanashiro.duarte@gmail.com>\n\ndjerius - Diab Jerius (cpan:DJERIUS) <djerius@cfa.harvard.edu>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 2010-2016 the Sub::Quote \"AUTHOR\" and \"CONTRIBUTORS\" as listed above.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This library is free software and may be distributed under the same terms as perl itself. See\n<http://dev.perl.org/licenses/>.\n",
            "subsections": []
        }
    },
    "summary": "Sub::Quote - Efficient generation of subroutines via string eval",
    "flags": [],
    "examples": [],
    "see_also": []
}