CINXE.COM

AutoLoader - load subroutines only on demand - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>AutoLoader - load subroutines only on demand - 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 AutoLoader - MetaCPAN" href="/dist/AutoLoader/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/AutoLoader" /> <meta name="description" content="load subroutines only on demand" /> <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/AutoLoader" /> <meta property="og:title" content="AutoLoader" /> <meta property="og:description" content="load subroutines only on demand" /> <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 AutoLoader was released."> <span class="relatize">25 Oct 2013 17:11:47 UTC</span> </div> </li> <li> Distribution: <a href="/dist/AutoLoader">AutoLoader</a> </li> <li> Module version: 5.74 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/AutoLoader/source/lib/AutoLoader.pm">Source</a> (<a href="/dist/AutoLoader/source/lib/AutoLoader.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/AutoLoader/source/lib">Browse</a> (<a href="/dist/AutoLoader/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/AutoLoader/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/AutoLoader/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="http://rt.perl.org/perlbug/">Issues</a> </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=AutoLoader+5.74" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/A/AutoLoader.html?oncpan=1&amp;distmat=1&amp;version=5.74&amp;grade=2" style="color: #090">2264</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/A/AutoLoader.html?oncpan=1&amp;distmat=1&amp;version=5.74&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/A/AutoLoader.html?oncpan=1&amp;distmat=1&amp;version=5.74&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/SMUELLER/AutoLoader-5.74">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on AutoLoader 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: 5 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/AutoLoader-5.74/index.html">26.12% Coverage </a> </li> <li> License: perl_5 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/AutoLoader/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/S/SM/SMUELLER/AutoLoader-5.74.tar.gz"> Download (<span itemprop="fileSize">29.82KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FSMUELLER%2FAutoLoader-5.74%2Flib%2FAutoLoader.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/AutoLoader/permissions"> Permissions </a> </li> <li> <a href="/dist/AutoLoader/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:AutoLoader"> <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="AutoLoader"> <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/SMUELLER/AutoLoader-5.74/view/lib/AutoLoader.pm" >5.74 (SMUELLER on 2013-10-25)</option> <optgroup label="BackPAN">' <option value="/release/SMUELLER/AutoLoader-5.73/view/lib/AutoLoader.pm" >5.73 (SMUELLER on 2012-10-16)</option> <option value="/release/SMUELLER/AutoLoader-5.72/view/lib/AutoLoader.pm" >5.72 (SMUELLER on 2011-11-24)</option> <option value="/release/SMUELLER/AutoLoader-5.71/view/lib/AutoLoader.pm" >5.71 (SMUELLER on 2010-11-20)</option> <option value="/release/SMUELLER/AutoLoader-5.70/view/lib/AutoLoader.pm" >5.70 (SMUELLER on 2009-09-21)</option> <option value="/release/SMUELLER/AutoLoader-5.69/view/lib/AutoLoader.pm" >5.69 (SMUELLER on 2009-08-08)</option> <option value="/release/SMUELLER/AutoLoader-5.68/view/lib/AutoLoader.pm" >5.68 (SMUELLER on 2009-01-05)</option> <option value="/release/SMUELLER/AutoLoader-5.67/view/lib/AutoLoader.pm" >5.67 (SMUELLER on 2008-09-12)</option> <option value="/release/SMUELLER/AutoLoader-5.66_02/view/lib/AutoLoader.pm" >5.66_02 DEV (SMUELLER on 2008-09-04)</option> <option value="/release/SMUELLER/AutoLoader-5.66_01/view/lib/AutoLoader.pm" >5.66_01 DEV (SMUELLER on 2008-09-02)</option> <option value="/release/SMUELLER/AutoLoader-5.66/view/lib/AutoLoader.pm" >5.66 (SMUELLER on 2008-05-14)</option> <option value="/release/SMUELLER/AutoLoader-5.65/view/lib/AutoLoader.pm" >5.65 (SMUELLER on 2008-05-13)</option> <option value="/release/SMUELLER/AutoLoader-5.64/view/lib/AutoLoader.pm" >5.64 (SMUELLER on 2007-12-26)</option> <option value="/release/SMUELLER/AutoLoader-5.63/view/lib/AutoLoader.pm" >5.63 (SMUELLER on 2007-01-17)</option> <option value="/release/SMUELLER/AutoLoader-5.62/view/lib/AutoLoader.pm" >5.62 (SMUELLER on 2007-01-16)</option> </optgroup> </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/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.74/lib/AutoLoader.pm" >5.74 (SMUELLER on 2013-10-25)</option> <optgroup label="BackPAN">' <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.73/lib/AutoLoader.pm" >5.73 (SMUELLER on 2012-10-16)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.72/lib/AutoLoader.pm" >5.72 (SMUELLER on 2011-11-24)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.71/lib/AutoLoader.pm" >5.71 (SMUELLER on 2010-11-20)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.70/lib/AutoLoader.pm" >5.70 (SMUELLER on 2009-09-21)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.69/lib/AutoLoader.pm" >5.69 (SMUELLER on 2009-08-08)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.68/lib/AutoLoader.pm" >5.68 (SMUELLER on 2009-01-05)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.67/lib/AutoLoader.pm" >5.67 (SMUELLER on 2008-09-12)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.66_02/lib/AutoLoader.pm" >5.66_02 DEV (SMUELLER on 2008-09-04)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.66_01/lib/AutoLoader.pm" >5.66_01 DEV (SMUELLER on 2008-09-02)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.66/lib/AutoLoader.pm" >5.66 (SMUELLER on 2008-05-14)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.65/lib/AutoLoader.pm" >5.65 (SMUELLER on 2008-05-13)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.64/lib/AutoLoader.pm" >5.64 (SMUELLER on 2007-12-26)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.63/lib/AutoLoader.pm" >5.63 (SMUELLER on 2007-01-17)</option> <option value="/release/SMUELLER/AutoLoader-5.74/diff/SMUELLER/AutoLoader-5.62/lib/AutoLoader.pm" >5.62 (SMUELLER on 2007-01-16)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><i class="ttip" title="dynamic_config enabled">unknown</i></li> <li> <hr> </li> <li> <a href="/module/AutoLoader/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=AutoLoader">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=AutoLoader">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/SMUELLER/AutoLoader-5.74/view/lib/AutoLoader.pm">This version</a> </li> <li> <a href="/pod/AutoLoader">Latest version</a> </li> <li> </li> <li> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/SMUELLER" class="author-name">Steffen Müller</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/SMUELLER/AutoLoader-5.74/view/lib/AutoLoader.pm" >5.74 (SMUELLER on 2013-10-25)</option> <optgroup label="BackPAN">' <option value="/release/SMUELLER/AutoLoader-5.73/view/lib/AutoLoader.pm" >5.73 (SMUELLER on 2012-10-16)</option> <option value="/release/SMUELLER/AutoLoader-5.72/view/lib/AutoLoader.pm" >5.72 (SMUELLER on 2011-11-24)</option> <option value="/release/SMUELLER/AutoLoader-5.71/view/lib/AutoLoader.pm" >5.71 (SMUELLER on 2010-11-20)</option> <option value="/release/SMUELLER/AutoLoader-5.70/view/lib/AutoLoader.pm" >5.70 (SMUELLER on 2009-09-21)</option> <option value="/release/SMUELLER/AutoLoader-5.69/view/lib/AutoLoader.pm" >5.69 (SMUELLER on 2009-08-08)</option> <option value="/release/SMUELLER/AutoLoader-5.68/view/lib/AutoLoader.pm" >5.68 (SMUELLER on 2009-01-05)</option> <option value="/release/SMUELLER/AutoLoader-5.67/view/lib/AutoLoader.pm" >5.67 (SMUELLER on 2008-09-12)</option> <option value="/release/SMUELLER/AutoLoader-5.66_02/view/lib/AutoLoader.pm" >5.66_02 DEV (SMUELLER on 2008-09-04)</option> <option value="/release/SMUELLER/AutoLoader-5.66_01/view/lib/AutoLoader.pm" >5.66_01 DEV (SMUELLER on 2008-09-02)</option> <option value="/release/SMUELLER/AutoLoader-5.66/view/lib/AutoLoader.pm" >5.66 (SMUELLER on 2008-05-14)</option> <option value="/release/SMUELLER/AutoLoader-5.65/view/lib/AutoLoader.pm" >5.65 (SMUELLER on 2008-05-13)</option> <option value="/release/SMUELLER/AutoLoader-5.64/view/lib/AutoLoader.pm" >5.64 (SMUELLER on 2007-12-26)</option> <option value="/release/SMUELLER/AutoLoader-5.63/view/lib/AutoLoader.pm" >5.63 (SMUELLER on 2007-01-17)</option> <option value="/release/SMUELLER/AutoLoader-5.62/view/lib/AutoLoader.pm" >5.62 (SMUELLER on 2007-01-16)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/AutoLoader">AutoLoader-5.74</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 three &#10; • 26 direct dependents &#10; • 287 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="#e4e2e2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="AutoLoader-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="AutoLoader-5.74"> <input type="hidden" name="author" value="SMUELLER"> <input type="hidden" name="distribution" value="AutoLoader"> <button type="submit" class="favorite"><span></span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite"><span></span> ++</button> </div> / <span>AutoLoader</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> <ul> <li><a href="#Subroutine-Stubs">Subroutine Stubs</a></li> <li><a href="#Using-AutoLoader%27s-AUTOLOAD-Subroutine">Using AutoLoader&#39;s AUTOLOAD Subroutine</a></li> <li><a href="#Overriding-AutoLoader%27s-AUTOLOAD-Subroutine">Overriding AutoLoader&#39;s AUTOLOAD Subroutine</a></li> <li><a href="#Package-Lexicals">Package Lexicals</a></li> <li><a href="#Not-Using-AutoLoader">Not Using AutoLoader</a></li> <li><a href="#AutoLoader-vs.-SelfLoader">AutoLoader vs. SelfLoader</a></li> <li><a href="#Forcing-AutoLoader-to-Load-a-Function">Forcing AutoLoader to Load a Function</a></li> </ul> </li> <li><a href="#CAVEATS">CAVEATS</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>AutoLoader - load subroutines only on demand</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>package Foo; use AutoLoader &#39;AUTOLOAD&#39;; # import the default AUTOLOAD subroutine package Bar; use AutoLoader; # don&#39;t import AUTOLOAD, define our own sub AUTOLOAD { ... $AutoLoader::AUTOLOAD = &quot;...&quot;; goto &amp;AutoLoader::AUTOLOAD; }</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>The <b>AutoLoader</b> module works with the <b>AutoSplit</b> module and the <code>__END__</code> token to defer the loading of some subroutines until they are used rather than loading them all at once.</p> <p>To use <b>AutoLoader</b>, the author of a module has to place the definitions of subroutines to be autoloaded after an <code>__END__</code> token. (See <a href="/pod/perldata">perldata</a>.) The <b>AutoSplit</b> module can then be run manually to extract the definitions into individual files <i>auto/funcname.al</i>.</p> <p><b>AutoLoader</b> implements an AUTOLOAD subroutine. When an undefined subroutine in is called in a client module of <b>AutoLoader</b>, <b>AutoLoader</b>&#39;s AUTOLOAD subroutine attempts to locate the subroutine in a file with a name related to the location of the file from which the client module was read. As an example, if <i>POSIX.pm</i> is located in <i>/usr/local/lib/perl5/POSIX.pm</i>, <b>AutoLoader</b> will look for perl subroutines <b>POSIX</b> in <i>/usr/local/lib/perl5/auto/POSIX/*.al</i>, where the <code>.al</code> file has the same name as the subroutine, sans package. If such a file exists, AUTOLOAD will read and evaluate it, thus (presumably) defining the needed subroutine. AUTOLOAD will then <code>goto</code> the newly defined subroutine.</p> <p>Once this process completes for a given function, it is defined, so future calls to the subroutine will bypass the AUTOLOAD mechanism.</p> <h2 id="Subroutine-Stubs"><a id="Subroutine"></a>Subroutine Stubs</h2> <p>In order for object method lookup and/or prototype checking to operate correctly even when methods have not yet been defined it is necessary to &quot;forward declare&quot; each subroutine (as in <code>sub NAME;</code>). See <a href="/pod/perlsub#SYNOPSIS">&quot;SYNOPSIS&quot; in perlsub</a>. Such forward declaration creates &quot;subroutine stubs&quot;, which are place holders with no code.</p> <p>The AutoSplit and <b>AutoLoader</b> modules automate the creation of forward declarations. The AutoSplit module creates an &#39;index&#39; file containing forward declarations of all the AutoSplit subroutines. When the AutoLoader module is &#39;use&#39;d it loads these declarations into its callers package.</p> <p>Because of this mechanism it is important that <b>AutoLoader</b> is always <code>use</code>d and not <code>require</code>d.</p> <h2 id="Using-AutoLoader&#39;s-AUTOLOAD-Subroutine"><a id="Using"></a><a id="Using-AutoLoaders-AUTOLOAD-Subroutine"></a>Using <b>AutoLoader</b>&#39;s AUTOLOAD Subroutine</h2> <p>In order to use <b>AutoLoader</b>&#39;s AUTOLOAD subroutine you <i>must</i> explicitly import it:</p> <pre><code>use AutoLoader &#39;AUTOLOAD&#39;;</code></pre> <h2 id="Overriding-AutoLoader&#39;s-AUTOLOAD-Subroutine"><a id="Overriding"></a><a id="Overriding-AutoLoaders-AUTOLOAD-Subroutine"></a>Overriding <b>AutoLoader</b>&#39;s AUTOLOAD Subroutine</h2> <p>Some modules, mainly extensions, provide their own AUTOLOAD subroutines. They typically need to check for some special cases (such as constants) and then fallback to <b>AutoLoader</b>&#39;s AUTOLOAD for the rest.</p> <p>Such modules should <i>not</i> import <b>AutoLoader</b>&#39;s AUTOLOAD subroutine. Instead, they should define their own AUTOLOAD subroutines along these lines:</p> <pre><code>use AutoLoader; use Carp; sub AUTOLOAD { my $sub = $AUTOLOAD; (my $constname = $sub) =~ s/.*:://; my $val = constant($constname, @_ ? $_[0] : 0); if ($! != 0) { if ($! =~ /Invalid/ || $!{EINVAL}) { $AutoLoader::AUTOLOAD = $sub; goto &amp;AutoLoader::AUTOLOAD; } else { croak &quot;Your vendor has not defined constant $constname&quot;; } } *$sub = sub { $val }; # same as: eval &quot;sub $sub { $val }&quot;; goto &amp;$sub; }</code></pre> <p>If any module&#39;s own AUTOLOAD subroutine has no need to fallback to the AutoLoader&#39;s AUTOLOAD subroutine (because it doesn&#39;t have any AutoSplit subroutines), then that module should not use <b>AutoLoader</b> at all.</p> <h2 id="Package-Lexicals"><a id="Package"></a>Package Lexicals</h2> <p>Package lexicals declared with <code>my</code> in the main block of a package using <b>AutoLoader</b> will not be visible to auto-loaded subroutines, due to the fact that the given scope ends at the <code>__END__</code> marker. A module using such variables as package globals will not work properly under the <b>AutoLoader</b>.</p> <p>The <code>vars</code> pragma (see <a href="/pod/perlmod#vars">&quot;vars&quot; in perlmod</a>) may be used in such situations as an alternative to explicitly qualifying all globals with the package namespace. Variables pre-declared with this pragma will be visible to any autoloaded routines (but will not be invisible outside the package, unfortunately).</p> <h2 id="Not-Using-AutoLoader"><a id="Not"></a>Not Using AutoLoader</h2> <p>You can stop using AutoLoader by simply</p> <pre><code>no AutoLoader;</code></pre> <h2 id="AutoLoader-vs.-SelfLoader"><a id="AutoLoader"></a><b>AutoLoader</b> vs. <b>SelfLoader</b></h2> <p>The <b>AutoLoader</b> is similar in purpose to <b>SelfLoader</b>: both delay the loading of subroutines.</p> <p><b>SelfLoader</b> uses the <code>__DATA__</code> marker rather than <code>__END__</code>. While this avoids the use of a hierarchy of disk files and the associated open/close for each routine loaded, <b>SelfLoader</b> suffers a startup speed disadvantage in the one-time parsing of the lines after <code>__DATA__</code>, after which routines are cached. <b>SelfLoader</b> can also handle multiple packages in a file.</p> <p><b>AutoLoader</b> only reads code as it is requested, and in many cases should be faster, but requires a mechanism like <b>AutoSplit</b> be used to create the individual files. <a href="/pod/ExtUtils::MakeMaker">ExtUtils::MakeMaker</a> will invoke <b>AutoSplit</b> automatically if <b>AutoLoader</b> is used in a module source file.</p> <h2 id="Forcing-AutoLoader-to-Load-a-Function"><a id="Forcing"></a>Forcing AutoLoader to Load a Function</h2> <p>Sometimes, it can be necessary or useful to make sure that a certain function is fully loaded by AutoLoader. This is the case, for example, when you need to wrap a function to inject debugging code. It is also helpful to force early loading of code before forking to make use of copy-on-write as much as possible.</p> <p>Starting with AutoLoader 5.73, you can call the <code>AutoLoader::autoload_sub</code> function with the fully-qualified name of the function to load from its <i>.al</i> file. The behaviour is exactly the same as if you called the function, triggering the regular <code>AUTOLOAD</code> mechanism, but it does not actually execute the autoloaded function.</p> <h1 id="CAVEATS">CAVEATS</h1> <p>AutoLoaders prior to Perl 5.002 had a slightly different interface. Any old modules which use <b>AutoLoader</b> should be changed to the new calling style. Typically this just means changing a require to a use, adding the explicit <code>&#39;AUTOLOAD&#39;</code> import if needed, and removing <b>AutoLoader</b> from <code>@ISA</code>.</p> <p>On systems with restrictions on file name length, the file corresponding to a subroutine may have a shorter name that the routine itself. This can lead to conflicting file names. The <i>AutoSplit</i> package warns of these potential conflicts when used to split a module.</p> <p>AutoLoader may fail to find the autosplit files (or even find the wrong ones) in cases where <code>@INC</code> contains relative paths, <b>and</b> the program does <code>chdir</code>.</p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <p><a href="/pod/SelfLoader">SelfLoader</a> - an autoloader that doesn&#39;t use external files.</p> <h1 id="AUTHOR">AUTHOR</h1> <p><code>AutoLoader</code> is maintained by the perl5-porters. Please direct any questions to the canonical mailing list. Anything that is applicable to the CPAN release can be sent to its maintainer, though.</p> <p>Author and Maintainer: The Perl5-Porters &lt;perl5-porters@perl.org&gt;</p> <p>Maintainer of the CPAN release: Steffen Mueller &lt;smueller@cpan.org&gt;</p> <h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1> <p>This package has been part of the perl core since the first release of perl5. It has been released separately to CPAN so older installations can benefit from bug fixes.</p> <p>This package has the same copyright and license as the perl core:</p> <pre><code> Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013 by Larry Wall and others All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the &quot;Artistic License&quot; which comes with this Kit. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details. You should have received a copy of the Artistic License with this Kit, in the file named &quot;Artistic&quot;. If not, I&#39;ll be glad to provide one. You should also have received a copy of the GNU General Public License along with this program in the file named &quot;Copying&quot;. If not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA or visit their web page on the internet at http://www.gnu.org/copyleft/gpl.html. For those of you that choose to use the GNU General Public License, my interpretation of the GNU General Public License is that no Perl script falls under the terms of the GPL unless you explicitly put said script under the terms of the GPL yourself. Furthermore, any object code linked with perl does not automatically fall under the terms of the GPL, provided such object code only adds definitions of subroutines and variables, and does not otherwise impair the resulting interpreter from executing any standard Perl script. I consider linking in C subroutines in this manner to be the moral equivalent of defining subroutines in the Perl language itself. You may sell such an object file as proprietary provided that you provide or offer to provide the Perl source, as specified by the GNU General Public License. (This is merely an alternate way of specifying input to the program.) You may also sell a binary produced by the dumping of a running Perl script that belongs to you, provided that you provide or offer to provide the Perl source as specified by the GPL. (The fact that a Perl interpreter and your code are in the same binary file is, in this case, a form of mere aggregation.) This is my interpretation of the GPL. If you still have concerns or difficulties understanding my intent, feel free to contact me. Of course, the Artistic License spells all this out for your protection, so you may prefer to use that.</code></pre></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 AutoLoader, 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 AutoLoader</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install AutoLoader</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