CINXE.COM

aliased - Use shorter versions of class names. - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>aliased - Use shorter versions of class names. - 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-C7YQGD7K.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of aliased - MetaCPAN" href="/dist/aliased/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/aliased" /> <meta name="description" content="Use shorter versions of class names." /> <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://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/aliased" /> <meta property="og:title" content="aliased" /> <meta property="og:description" content="Use shorter versions of class names." /> <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 class="top-notify-banner"> </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 aliased was released."> <span class="relatize">03 Jan 2015 20:41:20 UTC</span> </div> </li> <li> Distribution: <a href="/dist/aliased">aliased</a> </li> <li> Module version: 0.34 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/aliased/source/lib/aliased.pm">Source</a> (<a href="/dist/aliased/source/lib/aliased.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/aliased/source/lib">Browse</a> (<a href="/dist/aliased/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/aliased/changes">Changes</a> </li> <li> <a rel="noopener nofollow" class="nopopup" href="https://github.com/karenetheridge/aliased">Homepage</a> </li> <li> <a class="nopopup" href="/dist/aliased/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/karenetheridge/aliased">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=aliased">Issues</a> (4) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=aliased+0.34" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/a/aliased.html?oncpan=1&amp;distmat=1&amp;version=0.34&amp;grade=2" style="color: #090">2162</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/a/aliased.html?oncpan=1&amp;distmat=1&amp;version=0.34&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/a/aliased.html?oncpan=1&amp;distmat=1&amp;version=0.34&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/ETHER/aliased-0.34">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on aliased 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: 2 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/aliased-0.34/index.html">93.52% Coverage </a> </li> <li> License: perl_5 </li> <li> Perl: v5.6.0 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/aliased/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/E/ET/ETHER/aliased-0.34.tar.gz"> Download (<span itemprop="fileSize">29.75KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FETHER%2Faliased-0.34%2Flib%2Faliased.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/aliased/permissions"> Permissions </a> </li> <li> <a href="/dist/aliased/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:aliased"> <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="aliased"> <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/ETHER/aliased-0.34/view/lib/aliased.pm" >0.34 (ETHER on 2015-01-03)</option> <option value="/release/OVID/aliased-0.31/view/lib/aliased.pm" >0.31 (OVID on 2013-02-18)</option> <option value="/release/OVID/aliased-0.30_01/view/lib/aliased.pm" >0.30_01 DEV (OVID on 2010-01-03)</option> <option value="/release/OVID/aliased-0.30/view/lib/aliased.pm" >0.30 (OVID on 2009-08-05)</option> <option value="/release/OVID/aliased-0.22/view/lib/aliased.pm" >0.22 (OVID on 2008-02-12)</option> <option value="/release/OVID/aliased-0.21/view/lib/aliased.pm" >0.21 (OVID on 2007-03-29)</option> <optgroup label="BackPAN">' <option value="/release/ETHER/aliased-0.33/view/lib/aliased.pm" >0.33 (ETHER on 2014-12-21)</option> <option value="/release/OVID/aliased-0.20/view/lib/aliased.pm" >0.20 (OVID on 2005-09-23)</option> <option value="/release/OVID/aliased-0.11/view/lib/aliased.pm" >0.11 (OVID on 2005-01-07)</option> <option value="/release/OVID/aliased-0.1/view/lib/aliased.pm" >0.1 (OVID on 2005-01-07)</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/ETHER/aliased-0.34/diff/ETHER/aliased-0.34/lib/aliased.pm" >0.34 (ETHER on 2015-01-03)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.31/lib/aliased.pm" >0.31 (OVID on 2013-02-18)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.30_01/lib/aliased.pm" >0.30_01 DEV (OVID on 2010-01-03)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.30/lib/aliased.pm" >0.30 (OVID on 2009-08-05)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.22/lib/aliased.pm" >0.22 (OVID on 2008-02-12)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.21/lib/aliased.pm" >0.21 (OVID on 2007-03-29)</option> <optgroup label="BackPAN">' <option value="/release/ETHER/aliased-0.34/diff/ETHER/aliased-0.33/lib/aliased.pm" >0.33 (ETHER on 2014-12-21)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.20/lib/aliased.pm" >0.20 (OVID on 2005-09-23)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.11/lib/aliased.pm" >0.11 (OVID on 2005-01-07)</option> <option value="/release/ETHER/aliased-0.34/diff/OVID/aliased-0.1/lib/aliased.pm" >0.1 (OVID on 2005-01-07)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/Carp" title="Carp" class="ellipsis">Carp</a></li> <li><a href="/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li> <li><a href="/pod/strict" title="strict" class="ellipsis">strict</a></li> <li><a href="/pod/warnings" title="warnings" class="ellipsis">warnings</a></li> <li> <hr> </li> <li> <a href="/module/aliased/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=aliased">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=aliased">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/ETHER/aliased-0.34/view/lib/aliased.pm">This version</a> </li> <li> <a href="/pod/aliased">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/AERO"><img src="https://www.gravatar.com/avatar/c178cdf81a17c1c59c6ee898d9e09ccf?d=identicon&amp;s=20" title="AERO" alt="AERO"></a> <a class="display-all" href="/author/SSCAFFIDI"><img src="https://www.gravatar.com/avatar/2b2258ad3913c3d9a32123b905101a8b?d=identicon&amp;s=20" title="SSCAFFIDI" alt="SSCAFFIDI"></a> <a class="display-all" href="/author/ARJONES"><img src="https://www.gravatar.com/avatar/779fdd029141571e2650d9060978c1a1?d=identicon&amp;s=20" title="ARJONES" alt="ARJONES"></a> <a class="display-all" href="/author/DMOL"><img src="https://www.gravatar.com/avatar/78b28a931707c0fa696996adc7702db9?d=identicon&amp;s=20" title="DMOL" alt="DMOL"></a> <a class="display-all" href="/author/TMUELLER"><img src="https://www.gravatar.com/avatar/24e72fda49bd7c84d89bcaa475859ac4?d=identicon&amp;s=20" title="TMUELLER" alt="TMUELLER"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/aliased/plussers">22 PAUSE users</a> </div> <div> 12 non-PAUSE users </div> </div> </li> <li> <div> <button class="contributors-show-button btn-link">and 7 contributors</button> <div id="metacpan_contributors" class="slide-out slide-out-hidden"> <div> <ul> <li class="contributor" data-contrib-email="belden@shutterstock.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Belden Lyman </li> <li class="contributor" data-cpan-author="OVID" data-contrib-email="ovid@cpan.org" > <a href="/author/OVID" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/7f633daa0796788b31b868b5ffe98157?d=identicon&amp;s=20" /> Curtis &quot;Ovid&quot; Poe </a> </li> <li class="contributor" data-cpan-author="SPROUT" data-contrib-email="sprout@cpan.org" > <a href="/author/SPROUT" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/30bd18493bc25ab8d09ea1050dd28f47?d=identicon&amp;s=20" /> Father Chrysostomos </a> </li> <li class="contributor" data-contrib-email="rafl@debian.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Florian Ragwitz </li> <li class="contributor" data-contrib-email="xaerxess@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Grzegorz Rożniecki </li> <li class="contributor" data-cpan-author="DOLMEN" data-contrib-email="dolmen@cpan.org" > <a href="/author/DOLMEN" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/70d9b050bfe39350c234d710fadfcd39?d=identicon&amp;s=20" /> Olivier Mengué </a> </li> <li class="contributor" data-contrib-email="curtis_ovid_poe@yahoo.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Ovid </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/ETHER" class="author-name">Karen Etheridge</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/ETHER/aliased-0.34/view/lib/aliased.pm" >0.34 (ETHER on 2015-01-03)</option> <option value="/release/OVID/aliased-0.31/view/lib/aliased.pm" >0.31 (OVID on 2013-02-18)</option> <option value="/release/OVID/aliased-0.30_01/view/lib/aliased.pm" >0.30_01 DEV (OVID on 2010-01-03)</option> <option value="/release/OVID/aliased-0.30/view/lib/aliased.pm" >0.30 (OVID on 2009-08-05)</option> <option value="/release/OVID/aliased-0.22/view/lib/aliased.pm" >0.22 (OVID on 2008-02-12)</option> <option value="/release/OVID/aliased-0.21/view/lib/aliased.pm" >0.21 (OVID on 2007-03-29)</option> <optgroup label="BackPAN">' <option value="/release/ETHER/aliased-0.33/view/lib/aliased.pm" >0.33 (ETHER on 2014-12-21)</option> <option value="/release/OVID/aliased-0.20/view/lib/aliased.pm" >0.20 (OVID on 2005-09-23)</option> <option value="/release/OVID/aliased-0.11/view/lib/aliased.pm" >0.11 (OVID on 2005-01-07)</option> <option value="/release/OVID/aliased-0.1/view/lib/aliased.pm" >0.1 (OVID on 2005-01-07)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/aliased">aliased-0.34</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; • 123 direct dependents &#10; • 1155 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="aliased-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="aliased-0.34"> <input type="hidden" name="author" value="ETHER"> <input type="hidden" name="distribution" value="aliased"> <button type="submit" class="favorite highlight"><span>34</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>34</span> ++</button> </div> / <span>aliased</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="#VERSION">VERSION</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a> <ul> <li><a href="#Implicit-Aliasing">Implicit Aliasing</a></li> <li><a href="#Explicit-Aliasing">Explicit Aliasing</a></li> <li><a href="#Import-Lists">Import Lists</a></li> <li><a href="#alias()">alias()</a></li> <li><a href="#prefix()-(experimental)">prefix() (experimental)</a></li> <li><a href="#Why-OO-Only%3F">Why OO Only?</a></li> </ul> </li> <li><a href="#EXPORT">EXPORT</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#THANKS">THANKS</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li> <li><a href="#CONTRIBUTORS">CONTRIBUTORS</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>aliased - Use shorter versions of class names.</p> <h1 id="VERSION">VERSION</h1> <p>version 0.34</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code># Class name interface use aliased &#39;My::Company::Namespace::Customer&#39;; my $cust = Customer-&gt;new; use aliased &#39;My::Company::Namespace::Preferred::Customer&#39; =&gt; &#39;Preferred&#39;; my $pref = Preferred-&gt;new; # Variable interface use aliased; my $Customer = alias &quot;My::Other::Namespace::Customer&quot;; my $cust = $Customer-&gt;new; my $Preferred = alias &quot;My::Other::Namespace::Preferred::Customer&quot;; my $pref = $Preferred-&gt;new;</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p><code>aliased</code> is simple in concept but is a rather handy module. It loads the class you specify and exports into your namespace a subroutine that returns the class name. You can explicitly alias the class to another name or, if you prefer, you can do so implicitly. In the latter case, the name of the subroutine is the last part of the class name. Thus, it does something similar to the following:</p> <pre><code>#use aliased &#39;Some::Annoyingly::Long::Module::Name::Customer&#39;; use Some::Annoyingly::Long::Module::Name::Customer; sub Customer { return &#39;Some::Annoyingly::Long::Module::Name::Customer&#39;; } my $cust = Customer-&gt;new;</code></pre> <p>This module is useful if you prefer a shorter name for a class. It&#39;s also handy if a class has been renamed.</p> <p>(Some may object to the term &quot;aliasing&quot; because we&#39;re not aliasing one namespace to another, but it&#39;s a handy term. Just keep in mind that this is done with a subroutine and not with typeglobs and weird namespace munging.)</p> <p>Note that this is <b>only</b> for <code>use</code>ing OO modules. You cannot use this to load procedural modules. See the <a href="#Why-OO-Only%3F">&quot;Why OO Only?&quot;</a> section. Also, don&#39;t let the version number fool you. This code is ridiculously simple and is just fine for most use.</p> <h2 id="Implicit-Aliasing"><a id="Implicit"></a>Implicit Aliasing</h2> <p>The most common use of this module is:</p> <pre><code>use aliased &#39;Some::Module::name&#39;;</code></pre> <p><code>aliased</code> will allow you to reference the class by the last part of the class name. Thus, <code>Really::Long::Name</code> becomes <code>Name</code>. It does this by exporting a subroutine into your namespace with the same name as the aliased name. This subroutine returns the original class name.</p> <p>For example:</p> <pre><code>use aliased &quot;Acme::Company::Customer&quot;; my $cust = Customer-&gt;find($id);</code></pre> <p>Note that any class method can be called on the shorter version of the class name, not just the constructor.</p> <h2 id="Explicit-Aliasing"><a id="Explicit"></a>Explicit Aliasing</h2> <p>Sometimes two class names can cause a conflict (they both end with <code>Customer</code> for example), or you already have a subroutine with the same name as the aliased name. In that case, you can make an explicit alias by stating the name you wish to alias to:</p> <pre><code>use aliased &#39;Original::Module::Name&#39; =&gt; &#39;NewName&#39;;</code></pre> <p>Here&#39;s how we use <code>aliased</code> to avoid conflicts:</p> <pre><code>use aliased &quot;Really::Long::Name&quot;; use aliased &quot;Another::Really::Long::Name&quot; =&gt; &quot;Aname&quot;; my $name = Name-&gt;new; my $aname = Aname-&gt;new;</code></pre> <p>You can even alias to a different package:</p> <pre><code>use aliased &quot;Another::Really::Long::Name&quot; =&gt; &quot;Another::Name&quot;; my $aname = Another::Name-&gt;new;</code></pre> <p>Messing around with different namespaces is a really bad idea and you probably don&#39;t want to do this. However, it might prove handy if the module you are using has been renamed. If the interface has not changed, this allows you to use the new module by only changing one line of code.</p> <pre><code>use aliased &quot;New::Module::Name&quot; =&gt; &quot;Old::Module::Name&quot;; my $thing = Old::Module::Name-&gt;new;</code></pre> <h2 id="Import-Lists"><a id="Import"></a>Import Lists</h2> <p>Sometimes, even with an OO module, you need to specify extra arguments when using the module. When this happens, simply use <a href="#Explicit-Aliasing">&quot;Explicit Aliasing&quot;</a> followed by the import list:</p> <p>Snippet 1:</p> <pre><code>use Some::Module::Name qw/foo bar/; my $o = Some::Module::Name-&gt;some_class_method;</code></pre> <p>Snippet 2 (equivalent to snippet 1):</p> <pre><code>use aliased &#39;Some::Module::Name&#39; =&gt; &#39;Name&#39;, qw/foo bar/; my $o = Name-&gt;some_class_method;</code></pre> <p><b>Note</b>: remember, you cannot use import lists with <a href="#Implicit-Aliasing">&quot;Implicit Aliasing&quot;</a>. As a result, you may simply prefer to only use <a href="#Explicit-Aliasing">&quot;Explicit Aliasing&quot;</a> as a matter of style.</p> <h2 id="alias()"><a id="alias"></a>alias()</h2> <p>This function is only exported if you specify <code>use aliased</code> with no import list.</p> <pre><code>use aliased; my $alias = alias($class); my $alias = alias($class, @imports);</code></pre> <p><code>alias()</code> is an alternative to <code>use aliased ...</code> which uses less magic and avoids some of the ambiguities.</p> <p>Like <code>use aliased</code> it <code>use</code>s the <code>$class</code> (pass in <code>@imports</code>, if given) but instead of providing an <code>Alias</code> constant it simply returns a scalar set to the <code>$class</code> name.</p> <pre><code>my $thing = alias(&quot;Some::Thing::With::A::Long::Name&quot;); # Just like Some::Thing::With::A::Long::Name-&gt;method $thing-&gt;method;</code></pre> <p>The use of a scalar instead of a constant avoids any possible ambiguity when aliasing two similar names:</p> <pre><code># No ambiguity despite the fact that they both end with &quot;Name&quot; my $thing = alias(&quot;Some::Thing::With::A::Long::Name&quot;); my $other = alias(&quot;Some::Other::Thing::With::A::Long::Name&quot;);</code></pre> <p>and there is no magic constant exported into your namespace.</p> <p>The only caveat is loading of the $class happens at run time. If <code>$class</code> exports anything you might want to ensure it is loaded at compile time with:</p> <pre><code>my $thing; BEGIN { $thing = alias(&quot;Some::Thing&quot;); }</code></pre> <p>However, since OO classes rarely export this should not be necessary.</p> <h2 id="prefix()-(experimental)"><a id="prefix"></a><a id="prefix-experimental"></a>prefix() (experimental)</h2> <p>This function is only exported if you specify <code>use aliased</code> with no import list.</p> <pre><code>use aliased;</code></pre> <p>Sometimes you find you have a ton of packages in the same top-level namespace and you want to alias them, but only use them on demand. For example:</p> <pre><code># instead of: MailVerwaltung::Client::Exception::REST::Response-&gt;throw() my $error = prefix(&#39;MailVerwaltung::Client::Exception&#39;); $error-&gt;(&#39;REST::Response&#39;)-&gt;throw(); # same as above $error-&gt;()-&gt;throw; # same as MailVerwaltung::Client::Exception-&gt;throw</code></pre> <h2 id="Why-OO-Only?"><a id="Why"></a><a id="Why-OO-Only"></a>Why OO Only?</h2> <p>Some people have asked why this code only support object-oriented modules (OO). If I were to support normal subroutines, I would have to allow the following syntax:</p> <pre><code>use aliased &#39;Some::Really::Long::Module::Name&#39;; my $data = Name::data();</code></pre> <p>That causes a serious problem. The only (reasonable) way it can be done is to handle the aliasing via typeglobs. Thus, instead of a subroutine that provides the class name, we alias one package to another (as the <a href="/pod/namespace">namespace</a> module does.) However, we really don&#39;t want to simply alias one package to another and wipe out namespaces willy-nilly. By merely exporting a single subroutine to a namespace, we minimize the issue.</p> <p>Fortunately, this doesn&#39;t seem to be that much of a problem. Non-OO modules generally support exporting of the functions you need and this eliminates the need for a module such as this.</p> <h1 id="EXPORT">EXPORT</h1> <p>This modules exports a subroutine with the same name as the &quot;aliased&quot; name.</p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <p>The <a href="/pod/namespace">namespace</a> module.</p> <h1 id="THANKS">THANKS</h1> <p>Many thanks to Rentrak, Inc. (http://www.rentrak.com/) for graciously allowing me to replicate the functionality of some of their internal code.</p> <h1 id="AUTHOR">AUTHOR</h1> <p>Curtis &quot;Ovid&quot; Poe &lt;ovid@cpan.org&gt;</p> <h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1> <p>This software is copyright (c) 2005 by Curtis &quot;Ovid&quot; Poe.</p> <p>This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.</p> <h1 id="CONTRIBUTORS">CONTRIBUTORS</h1> <ul> <li><p>Karen Etheridge &lt;ether@cpan.org&gt;</p> </li> <li><p>Curtis Poe &lt;ovid@cpan.org&gt;</p> </li> <li><p>Ovid &lt;curtis_ovid_poe@yahoo.com&gt;</p> </li> <li><p>Florian Ragwitz &lt;rafl@debian.org&gt;</p> </li> <li><p>Grzegorz Ro&#x17C;niecki &lt;xaerxess@gmail.com&gt;</p> </li> <li><p>Father Chrysostomos &lt;sprout@cpan.org&gt;</p> </li> <li><p>Belden Lyman &lt;belden@shutterstock.com&gt;</p> </li> <li><p>Olivier Mengu&eacute; &lt;dolmen@cpan.org&gt;</p> </li> </ul></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 aliased, 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 aliased</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install aliased</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