CINXE.COM

Sub::Quote - Efficient generation of subroutines via string eval - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>Sub::Quote - Efficient generation of subroutines via string eval - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Sub-Quote - MetaCPAN" href="/dist/Sub-Quote/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/Sub::Quote" /> <meta name="description" content="Efficient generation of subroutines via string eval" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/Sub::Quote" /> <meta property="og:title" content="Sub::Quote" /> <meta property="og:description" content="Efficient generation of subroutines via string eval" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Sub-Quote was released."> <span class="relatize">20 Jan 2023 10:28:03 UTC</span> </div> </li> <li> Distribution: <a href="/dist/Sub-Quote">Sub-Quote</a> </li> <li> Module version: 2.006008 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/Sub-Quote/source/lib/Sub/Quote.pm">Source</a> (<a href="/dist/Sub-Quote/source/lib/Sub/Quote.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/Sub-Quote/source/lib/Sub">Browse</a> (<a href="/dist/Sub-Quote/source/lib/Sub?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/Sub-Quote/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/Sub-Quote/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/moose/Sub-Quote">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Sub-Quote">Issues</a> (2) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Sub-Quote+2.006008" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/S/Sub-Quote.html?oncpan=1&amp;distmat=1&amp;version=2.006008&amp;grade=2" style="color: #090">4211</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/S/Sub-Quote.html?oncpan=1&amp;distmat=1&amp;version=2.006008&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/S/Sub-Quote.html?oncpan=1&amp;distmat=1&amp;version=2.006008&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/HAARG/Sub-Quote-2.006008">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Sub-Quote who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 6 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/Sub-Quote-2.006008/index.html">92.11% Coverage </a> </li> <li> License: perl_5 </li> <li> Perl: v5.6.0 </li> <li class="chat-banner"> <div><a rel="noopener nofollow" target="_blank" href="https://kiwiirc.com/nextclient/#irc://irc.perl.org/#moose?nick=mc-guest-?">Chat with us!</a></div> </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/Sub-Quote/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/H/HA/HAARG/Sub-Quote-2.006008.tar.gz"> Download (<span itemprop="fileSize">35.08KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FHAARG%2FSub-Quote-2.006008%2Flib%2FSub%2FQuote.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/Sub-Quote/permissions"> Permissions </a> </li> <li> <a href="/dist/Sub-Quote/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:Sub-Quote"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="Sub-Quote"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/HAARG/Sub-Quote-2.006008/view/lib/Sub/Quote.pm" >2.006008 (HAARG on 2023-01-20)</option> <option value="/release/HAARG/Sub-Quote-2.006_007/view/lib/Sub/Quote.pm" >2.006_007 DEV (HAARG on 2022-04-05)</option> <option value="/release/HAARG/Sub-Quote-2.006006/view/lib/Sub/Quote.pm" >2.006006 (HAARG on 2019-10-01)</option> <option value="/release/HAARG/Sub-Quote-2.006_005/view/lib/Sub/Quote.pm" >2.006_005 DEV (HAARG on 2019-09-06)</option> <option value="/release/HAARG/Sub-Quote-2.006_004/view/lib/Sub/Quote.pm" >2.006_004 DEV (HAARG on 2019-04-24)</option> <option value="/release/HAARG/Sub-Quote-2.006003/view/lib/Sub/Quote.pm" >2.006003 (HAARG on 2019-03-10)</option> <option value="/release/HAARG/Sub-Quote-2.006_002/view/lib/Sub/Quote.pm" >2.006_002 DEV (HAARG on 2019-01-29)</option> <option value="/release/HAARG/Sub-Quote-2.006_001/view/lib/Sub/Quote.pm" >2.006_001 DEV (HAARG on 2019-01-07)</option> <option value="/release/HAARG/Sub-Quote-2.006_000/view/lib/Sub/Quote.pm" >2.006_000 DEV (HAARG on 2018-12-29)</option> <option value="/release/HAARG/Sub-Quote-2.005001/view/lib/Sub/Quote.pm" >2.005001 (HAARG on 2018-04-20)</option> <option value="/release/HAARG/Sub-Quote-2.005000/view/lib/Sub/Quote.pm" >2.005000 (HAARG on 2018-02-06)</option> <option value="/release/HAARG/Sub-Quote-2.004000/view/lib/Sub/Quote.pm" >2.004000 (HAARG on 2017-06-07)</option> <option value="/release/HAARG/Sub-Quote-2.003001/view/lib/Sub/Quote.pm" >2.003001 (HAARG on 2016-12-09)</option> <option value="/release/HAARG/Sub-Quote-2.003000/view/lib/Sub/Quote.pm" >2.003000 (HAARG on 2016-12-09)</option> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006008/lib/Sub/Quote.pm" >2.006008 (HAARG on 2023-01-20)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006_007/lib/Sub/Quote.pm" >2.006_007 DEV (HAARG on 2022-04-05)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006006/lib/Sub/Quote.pm" >2.006006 (HAARG on 2019-10-01)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006_005/lib/Sub/Quote.pm" >2.006_005 DEV (HAARG on 2019-09-06)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006_004/lib/Sub/Quote.pm" >2.006_004 DEV (HAARG on 2019-04-24)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006003/lib/Sub/Quote.pm" >2.006003 (HAARG on 2019-03-10)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006_002/lib/Sub/Quote.pm" >2.006_002 DEV (HAARG on 2019-01-29)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006_001/lib/Sub/Quote.pm" >2.006_001 DEV (HAARG on 2019-01-07)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.006_000/lib/Sub/Quote.pm" >2.006_000 DEV (HAARG on 2018-12-29)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.005001/lib/Sub/Quote.pm" >2.005001 (HAARG on 2018-04-20)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.005000/lib/Sub/Quote.pm" >2.005000 (HAARG on 2018-02-06)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.004000/lib/Sub/Quote.pm" >2.004000 (HAARG on 2017-06-07)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.003001/lib/Sub/Quote.pm" >2.003001 (HAARG on 2016-12-09)</option> <option value="/release/HAARG/Sub-Quote-2.006008/diff/HAARG/Sub-Quote-2.003000/lib/Sub/Quote.pm" >2.003000 (HAARG on 2016-12-09)</option> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/Scalar::Util" title="Scalar::Util" class="ellipsis">Scalar::Util</a></li> <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li> <li> <hr> </li> <li> <a href="/module/Sub::Quote/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=Sub%3A%3AQuote">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=Sub-Quote">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/HAARG/Sub-Quote-2.006008/view/lib/Sub/Quote.pm">This version</a> </li> <li> <a href="/pod/Sub::Quote">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/ETHER"><img src="https://www.gravatar.com/avatar/bdc5cd06679e732e262f6c1b450a0237?d=identicon&amp;s=20" title="ETHER" alt="ETHER"></a> <a class="display-all" href="/author/RRWO"><img src="https://www.gravatar.com/avatar/4a5274bc5d690ee3d619f044778771a7?d=identicon&amp;s=20" title="RRWO" alt="RRWO"></a> <a class="display-all" href="/author/JMATES"><img src="https://www.gravatar.com/avatar/06accb84e6519284be3941ff72e429cb?d=identicon&amp;s=20" title="JMATES" alt="JMATES"></a> <a class="display-all" href="/author/VEESH"><img src="https://www.gravatar.com/avatar/5ec5a5223fe6ee8e96b03dca47b670ea?d=identicon&amp;s=20" title="VEESH" alt="VEESH"></a> <a class="display-all" href="/author/SRCHULO"><img src="https://www.gravatar.com/avatar/6e788aafb8d791ad29046296ee0c5e4b?d=identicon&amp;s=20" title="SRCHULO" alt="SRCHULO"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/Sub-Quote/plussers">5 PAUSE users</a> </div> <div> 4 non-PAUSE users </div> </div> </li> <li> <div> <button class="contributors-show-button btn-link">and 1 contributors</button> <div id="metacpan_contributors" class="slide-out slide-out-hidden"> <div> <ul> <li class="contributor" data-contrib-email="mst@shadowcat.co.uk" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> mst - Matt S. Trout (cpan:MSTROUT) </li> </ul> </div> </div> </div> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/HAARG" class="author-name">Graham Knop</a> </span> <span>&nbsp;/&nbsp;</span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/HAARG/Sub-Quote-2.006008/view/lib/Sub/Quote.pm" >2.006008 (HAARG on 2023-01-20)</option> <option value="/release/HAARG/Sub-Quote-2.006_007/view/lib/Sub/Quote.pm" >2.006_007 DEV (HAARG on 2022-04-05)</option> <option value="/release/HAARG/Sub-Quote-2.006006/view/lib/Sub/Quote.pm" >2.006006 (HAARG on 2019-10-01)</option> <option value="/release/HAARG/Sub-Quote-2.006_005/view/lib/Sub/Quote.pm" >2.006_005 DEV (HAARG on 2019-09-06)</option> <option value="/release/HAARG/Sub-Quote-2.006_004/view/lib/Sub/Quote.pm" >2.006_004 DEV (HAARG on 2019-04-24)</option> <option value="/release/HAARG/Sub-Quote-2.006003/view/lib/Sub/Quote.pm" >2.006003 (HAARG on 2019-03-10)</option> <option value="/release/HAARG/Sub-Quote-2.006_002/view/lib/Sub/Quote.pm" >2.006_002 DEV (HAARG on 2019-01-29)</option> <option value="/release/HAARG/Sub-Quote-2.006_001/view/lib/Sub/Quote.pm" >2.006_001 DEV (HAARG on 2019-01-07)</option> <option value="/release/HAARG/Sub-Quote-2.006_000/view/lib/Sub/Quote.pm" >2.006_000 DEV (HAARG on 2018-12-29)</option> <option value="/release/HAARG/Sub-Quote-2.005001/view/lib/Sub/Quote.pm" >2.005001 (HAARG on 2018-04-20)</option> <option value="/release/HAARG/Sub-Quote-2.005000/view/lib/Sub/Quote.pm" >2.005000 (HAARG on 2018-02-06)</option> <option value="/release/HAARG/Sub-Quote-2.004000/view/lib/Sub/Quote.pm" >2.004000 (HAARG on 2017-06-07)</option> <option value="/release/HAARG/Sub-Quote-2.003001/view/lib/Sub/Quote.pm" >2.003001 (HAARG on 2016-12-09)</option> <option value="/release/HAARG/Sub-Quote-2.003000/view/lib/Sub/Quote.pm" >2.003000 (HAARG on 2016-12-09)</option> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/Sub-Quote">Sub-Quote-2.006008</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage four &#10; • 57 direct dependents &#10; • 7413 total dependents </title> <rect x="0" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="5" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="10" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="15" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="Sub-Quote-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="Sub-Quote-2.006008"> <input type="hidden" name="author" value="HAARG"> <input type="hidden" name="distribution" value="Sub-Quote"> <button type="submit" class="favorite highlight"><span>9</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>9</span> ++</button> </div> / <span>Sub::Quote</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a></li> <li><a href="#SUBROUTINES">SUBROUTINES</a> <ul> <li><a href="#quote_sub">quote_sub</a> <ul> <li><a href="#options">options</a></li> </ul> </li> <li><a href="#unquote_sub">unquote_sub</a></li> <li><a href="#quoted_from_sub">quoted_from_sub</a></li> <li><a href="#inlinify">inlinify</a></li> <li><a href="#quotify">quotify</a></li> <li><a href="#capture_unroll">capture_unroll</a></li> <li><a href="#qsub">qsub</a></li> <li><a href="#sanitize_identifier">sanitize_identifier</a></li> </ul> </li> <li><a href="#ENVIRONMENT">ENVIRONMENT</a> <ul> <li><a href="#SUB_QUOTE_DEBUG">SUB_QUOTE_DEBUG</a></li> </ul> </li> <li><a href="#CAVEATS">CAVEATS</a> <ul> <li><a href="#return">return</a></li> <li><a href="#pragmas">pragmas</a></li> </ul> </li> <li><a href="#SUPPORT">SUPPORT</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#CONTRIBUTORS">CONTRIBUTORS</a></li> <li><a href="#COPYRIGHT">COPYRIGHT</a></li> <li><a href="#LICENSE">LICENSE</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>Sub::Quote - Efficient generation of subroutines via string eval</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>package Silly; use Sub::Quote qw(quote_sub unquote_sub quoted_from_sub); quote_sub &#39;Silly::kitty&#39;, q{ print &quot;meow&quot; }; quote_sub &#39;Silly::doggy&#39;, q{ print &quot;woof&quot; }; my $sound = 0; quote_sub &#39;Silly::dagron&#39;, q{ print ++$sound % 2 ? &#39;burninate&#39; : &#39;roar&#39; }, { &#39;$sound&#39; =&gt; \$sound };</code></pre> <p>And elsewhere:</p> <pre><code>Silly-&gt;kitty; # meow Silly-&gt;doggy; # woof Silly-&gt;dagron; # burninate Silly-&gt;dagron; # roar Silly-&gt;dagron; # burninate</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>This package provides performant ways to generate subroutines from strings.</p> <h1 id="SUBROUTINES">SUBROUTINES</h1> <h2 id="quote_sub">quote_sub</h2> <pre><code>my $coderef = quote_sub &#39;Foo::bar&#39;, q{ print $x++ . &quot;\n&quot; }, { &#39;$x&#39; =&gt; \0 };</code></pre> <p>Arguments: ?$name, $code, ?\%captures, ?\%options</p> <p><code>$name</code> is the subroutine where the coderef will be installed.</p> <p><code>$code</code> is a string that will be turned into code.</p> <p><code>\%captures</code> is a hashref of variables that will be made available to the code. The keys should be the full name of the variable to be made available, including the sigil. The values should be references to the values. The variables will contain copies of the values. See the <a href="#SYNOPSIS">&quot;SYNOPSIS&quot;</a>&#39;s <code>Silly::dagron</code> for an example using captures.</p> <p>Exported by default.</p> <h3 id="options">options</h3> <dl> <dt id="no_install"><code>no_install</code></dt> <dd> <p><b>Boolean</b>. Set this option to not install the generated coderef into the passed subroutine name on undefer.</p> </dd> <dt id="no_defer"><code>no_defer</code></dt> <dd> <p><b>Boolean</b>. Prevents a Sub::Defer wrapper from being generated for the quoted sub. If the sub will most likely be called at some point, setting this is a good idea. For a sub that will most likely be inlined, it is not recommended.</p> </dd> <dt id="package"><code>package</code></dt> <dd> <p>The package that the quoted sub will be evaluated in. If not specified, the package from sub calling <code>quote_sub</code> will be used.</p> </dd> <dt id="hints"><code>hints</code></dt> <dd> <p>The value of <a href="/pod/ perlvar#%24%5EH"><code>$^H</code> </a> to use for the code being evaluated. This captures the settings of the <a href="/pod/strict">strict</a> pragma. If not specified, the value from the calling code will be used.</p> </dd> <dt id="warning_bits"><code>warning_bits</code></dt> <dd> <p>The value of <a href="/pod/ perlvar#%24%7B%5EWARNING_BITS%7D"><code>${^WARNING_BITS}</code> </a> to use for the code being evaluated. This captures the <a href="/pod/warnings">warnings</a> set. If not specified, the warnings from the calling code will be used.</p> </dd> <dt id="%^H"><a id="H"></a><code>%^H</code></dt> <dd> <p>The value of <a href="/pod/ perlvar#%25%5EH"><code>%^H</code> </a> to use for the code being evaluated. This captures additional pragma settings. If not specified, the value from the calling code will be used if possible (on perl 5.10+).</p> </dd> <dt id="attributes"><code>attributes</code></dt> <dd> <p>The <a href="/pod/perlsub#Subroutine-Attributes">&quot;Subroutine Attributes&quot; in perlsub</a> to apply to the sub generated. Should be specified as an array reference. The attributes will be applied to both the generated sub and the deferred wrapper, if one is used.</p> </dd> <dt id="file"><code>file</code></dt> <dd> <p>The apparent filename to use for the code being evaluated.</p> </dd> <dt id="line"><code>line</code></dt> <dd> <p>The apparent line number to use for the code being evaluated.</p> </dd> </dl> <h2 id="unquote_sub">unquote_sub</h2> <pre><code>my $coderef = unquote_sub $sub;</code></pre> <p>Forcibly replace subroutine with actual code.</p> <p>If $sub is not a quoted sub, this is a no-op.</p> <p>Exported by default.</p> <h2 id="quoted_from_sub">quoted_from_sub</h2> <pre><code>my $data = quoted_from_sub $sub; my ($name, $code, $captures, $compiled_sub) = @$data;</code></pre> <p>Returns original arguments to quote_sub, plus the compiled version if this sub has already been unquoted.</p> <p>Note that $sub can be either the original quoted version or the compiled version for convenience.</p> <p>Exported by default.</p> <h2 id="inlinify">inlinify</h2> <pre><code>my $prelude = capture_unroll &#39;$captures&#39;, { &#39;$x&#39; =&gt; 1, &#39;$y&#39; =&gt; 2, }, 4; my $inlined_code = inlinify q{ my ($x, $y) = @_; print $x + $y . &quot;\n&quot;; }, &#39;$x, $y&#39;, $prelude;</code></pre> <p>Takes a string of code, a string of arguments, a string of code which acts as a &quot;prelude&quot;, and a <b>Boolean</b> representing whether or not to localize the arguments.</p> <h2 id="quotify">quotify</h2> <pre><code>my $quoted_value = quotify $value;</code></pre> <p>Quotes a single (non-reference) scalar value for use in a code string. The result should reproduce the original value, including strings, undef, integers, and floating point numbers. The resulting floating point numbers (including infinites and not a number) should be precisely equal to the original, if possible. The exact format of the resulting number should not be relied on, as it may include hex floats or math expressions.</p> <h2 id="capture_unroll">capture_unroll</h2> <pre><code>my $prelude = capture_unroll &#39;$captures&#39;, { &#39;$x&#39; =&gt; 1, &#39;$y&#39; =&gt; 2, }, 4;</code></pre> <p>Arguments: $from, \%captures, $indent</p> <p>Generates a snippet of code which is suitable to be used as a prelude for <a href="#inlinify">&quot;inlinify&quot;</a>. <code>$from</code> is a string will be used as a hashref in the resulting code. The keys of <code>%captures</code> are the names of the variables and the values are ignored. <code>$indent</code> is the number of spaces to indent the result by.</p> <h2 id="qsub">qsub</h2> <pre><code>my $hash = { coderef =&gt; qsub q{ print &quot;hello&quot;; }, other =&gt; 5, };</code></pre> <p>Arguments: $code</p> <p>Works exactly like <a href="#quote_sub">&quot;quote_sub&quot;</a>, but includes a prototype to only accept a single parameter. This makes it easier to include in hash structures or lists.</p> <p>Exported by default.</p> <h2 id="sanitize_identifier">sanitize_identifier</h2> <pre><code>my $var_name = &#39;$variable_for_&#39; . sanitize_identifier(&#39;@name&#39;); quote_sub qq{ print \$${var_name} }, { $var_name =&gt; \$value };</code></pre> <p>Arguments: $identifier</p> <p>Sanitizes a value so that it can be used in an identifier.</p> <h1 id="ENVIRONMENT">ENVIRONMENT</h1> <h2 id="SUB_QUOTE_DEBUG">SUB_QUOTE_DEBUG</h2> <p>Causes code to be output to <code>STDERR</code> before being evaled. Several forms are supported:</p> <dl> <dt id="1"><a id="pod1"></a><code>1</code></dt> <dd> <p>All subs will be output.</p> </dd> <dt id="/foo/"><a id="foo"></a><code>/foo/</code></dt> <dd> <p>Subs will be output if their code matches the given regular expression.</p> </dd> <dt id="simple_identifier"><code>simple_identifier</code></dt> <dd> <p>Any sub with the given name will be output.</p> </dd> <dt id="Full::identifier"><a id="Full"></a><code>Full::identifier</code></dt> <dd> <p>A sub matching the full name will be output.</p> </dd> <dt id="Package::Name::"><a id="Package"></a><a id="Package::Name"></a><code>Package::Name::</code></dt> <dd> <p>Any sub in the given package (including anonymous subs) will be output.</p> </dd> </dl> <h1 id="CAVEATS">CAVEATS</h1> <p>Much of this is just string-based code-generation, and as a result, a few caveats apply.</p> <h2 id="return">return</h2> <p>Calling <code>return</code> from a quote_sub&#39;ed sub will not likely do what you intend. Instead of returning from the code you defined in <code>quote_sub</code>, it will return from the overall function it is composited into.</p> <p>So when you pass in:</p> <pre><code>quote_sub q{ return 1 if $condition; $morecode }</code></pre> <p>It might turn up in the intended context as follows:</p> <pre><code>sub foo { &lt;important code a&gt; do { return 1 if $condition; $morecode }; &lt;important code b&gt; }</code></pre> <p>Which will obviously return from foo, when all you meant to do was return from the code context in quote_sub and proceed with running important code b.</p> <h2 id="pragmas">pragmas</h2> <p><code>Sub::Quote</code> preserves the environment of the code creating the quoted subs. This includes the package, strict, warnings, and any other lexical pragmas. This is done by prefixing the code with a block that sets up a matching environment. When inlining <code>Sub::Quote</code> subs, care should be taken that user pragmas won&#39;t effect the rest of the code.</p> <h1 id="SUPPORT">SUPPORT</h1> <p>Users&#39; IRC: #moose on irc.perl.org</p> <p><a href="http://chat.mibbit.com/#moose@irc.perl.org">(click for instant chatroom login) </a></p> <p>Development and contribution IRC: #web-simple on irc.perl.org</p> <p><a href="http://chat.mibbit.com/#web-simple@irc.perl.org">(click for instant chatroom login) </a></p> <p>Bugtracker: <a href="https://rt.cpan.org/Public/Dist/Display.html?Name=Sub-Quote">https://rt.cpan.org/Public/Dist/Display.html?Name=Sub-Quote</a></p> <p>Git repository: <a>git://github.com/moose/Sub-Quote.git</a></p> <p>Git browser: <a href="https://github.com/moose/Sub-Quote">https://github.com/moose/Sub-Quote</a></p> <h1 id="AUTHOR">AUTHOR</h1> <p>mst - Matt S. Trout (cpan:MSTROUT) &lt;mst@shadowcat.co.uk&gt;</p> <h1 id="CONTRIBUTORS">CONTRIBUTORS</h1> <p>frew - Arthur Axel &quot;fREW&quot; Schmidt (cpan:FREW) &lt;frioux@gmail.com&gt;</p> <p>ribasushi - Peter Rabbitson (cpan:RIBASUSHI) &lt;ribasushi@cpan.org&gt;</p> <p>Mithaldu - Christian Walde (cpan:MITHALDU) &lt;walde.christian@googlemail.com&gt;</p> <p>tobyink - Toby Inkster (cpan:TOBYINK) &lt;tobyink@cpan.org&gt;</p> <p>haarg - Graham Knop (cpan:HAARG) &lt;haarg@cpan.org&gt;</p> <p>bluefeet - Aran Deltac (cpan:BLUEFEET) &lt;bluefeet@gmail.com&gt;</p> <p>ether - Karen Etheridge (cpan:ETHER) &lt;ether@cpan.org&gt;</p> <p>dolmen - Olivier Mengu&eacute; (cpan:DOLMEN) &lt;dolmen@cpan.org&gt;</p> <p>alexbio - Alessandro Ghedini (cpan:ALEXBIO) &lt;alexbio@cpan.org&gt;</p> <p>getty - Torsten Raudssus (cpan:GETTY) &lt;torsten@raudss.us&gt;</p> <p>arcanez - Justin Hunter (cpan:ARCANEZ) &lt;justin.d.hunter@gmail.com&gt;</p> <p>kanashiro - Lucas Kanashiro (cpan:KANASHIRO) &lt;kanashiro.duarte@gmail.com&gt;</p> <p>djerius - Diab Jerius (cpan:DJERIUS) &lt;djerius@cfa.harvard.edu&gt;</p> <h1 id="COPYRIGHT">COPYRIGHT</h1> <p>Copyright (c) 2010-2016 the Sub::Quote <a href="#AUTHOR">&quot;AUTHOR&quot;</a> and <a href="#CONTRIBUTORS">&quot;CONTRIBUTORS&quot;</a> as listed above.</p> <h1 id="LICENSE">LICENSE</h1> <p>This library is free software and may be distributed under the same terms as perl itself. See <a href="http://dev.perl.org/licenses/">http://dev.perl.org/licenses/</a>.</p></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install Sub::Quote, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm Sub::Quote</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install Sub::Quote</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10