CINXE.COM

NEXT - Provide a pseudo-class NEXT (et al) that allows method redispatch - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>NEXT - Provide a pseudo-class NEXT (et al) that allows method redispatch - 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 NEXT - MetaCPAN" href="/dist/NEXT/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/NEXT" /> <meta name="description" content="Provide a pseudo-class NEXT (et al) that allows method redispatch" /> <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/NEXT" /> <meta property="og:title" content="NEXT" /> <meta property="og:description" content="Provide a pseudo-class NEXT (et al) that allows method redispatch" /> <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 NEXT was released."> <span class="relatize">19 Jan 2022 11:21:25 UTC</span> </div> </li> <li> Distribution: <a href="/dist/NEXT">NEXT</a> </li> <li> Module version: 0.69 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/NEXT/source/lib/NEXT.pm">Source</a> (<a href="/dist/NEXT/source/lib/NEXT.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/NEXT/source/lib">Browse</a> (<a href="/dist/NEXT/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/NEXT/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/NEXT/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/neilb/next">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=NEXT">Issues</a> (3) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=NEXT+0.69" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/N/NEXT.html?oncpan=1&amp;distmat=1&amp;version=0.69&amp;grade=2" style="color: #090">1035</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/N/NEXT.html?oncpan=1&amp;distmat=1&amp;version=0.69&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/N/NEXT.html?oncpan=1&amp;distmat=1&amp;version=0.69&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/NEILB/NEXT-0.69">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on NEXT 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/NEXT-0.69/index.html">83.59% 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/NEXT/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/N/NE/NEILB/NEXT-0.69.tar.gz"> Download (<span itemprop="fileSize">11.81KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FNEILB%2FNEXT-0.69%2Flib%2FNEXT.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/NEXT/permissions"> Permissions </a> </li> <li> <a href="/dist/NEXT/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:NEXT"> <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="NEXT"> <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/NEILB/NEXT-0.69/view/lib/NEXT.pm" >0.69 (NEILB on 2022-01-19)</option> <optgroup label="BackPAN">' <option value="/release/NEILB/NEXT-0.68/view/lib/NEXT.pm" >0.68 (NEILB on 2021-04-19)</option> <option value="/release/NEILB/NEXT-0.67_03/view/lib/NEXT.pm" >0.67_03 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.67_02/view/lib/NEXT.pm" >0.67_02 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.67_01/view/lib/NEXT.pm" >0.67_01 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.67/view/lib/NEXT.pm" >0.67 (NEILB on 2016-07-30)</option> <option value="/release/NEILB/NEXT-0.66/view/lib/NEXT.pm" >0.66 (NEILB on 2016-07-28)</option> <option value="/release/NEILB/NEXT-0.65_01/view/lib/NEXT.pm" >0.65_01 DEV (NEILB on 2016-07-20)</option> <option value="/release/FLORA/NEXT-0.65/view/lib/NEXT.pm" >0.65 (FLORA on 2010-09-20)</option> <option value="/release/FLORA/NEXT-0.64/view/lib/NEXT.pm" >0.64 (FLORA on 2009-06-08)</option> <option value="/release/FLORA/NEXT-0.63/view/lib/NEXT.pm" >0.63 (FLORA on 2009-04-10)</option> <option value="/release/FLORA/NEXT-0.62/view/lib/NEXT.pm" >0.62 (FLORA on 2009-04-08)</option> <option value="/release/FLORA/NEXT-0.61/view/lib/NEXT.pm" >0.61 (FLORA on 2009-03-24)</option> <option value="/release/DCONWAY/NEXT-0.60/view/lib/NEXT.pm" >0.60 (DCONWAY on 2003-08-13)</option> <option value="/release/DCONWAY/NEXT-0.52/view/lib/NEXT.pm" >0.52 (DCONWAY on 2003-07-31)</option> <option value="/release/DCONWAY/NEXT-0.51/view/lib/NEXT.pm" >0.51 (DCONWAY on 2003-07-30)</option> <option value="/release/DCONWAY/NEXT-0.50/view/lib/NEXT.pm" >0.50 (DCONWAY on 2001-11-16)</option> <option value="/release/DCONWAY/NEXT-0.02/view/lib/NEXT.pm" >0.02 (DCONWAY on 2001-09-02)</option> <option value="/release/DCONWAY/NEXT-0.01/view/lib/NEXT.pm" >0.01 (DCONWAY on 2001-04-12)</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/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.69/lib/NEXT.pm" >0.69 (NEILB on 2022-01-19)</option> <optgroup label="BackPAN">' <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.68/lib/NEXT.pm" >0.68 (NEILB on 2021-04-19)</option> <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.67_03/lib/NEXT.pm" >0.67_03 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.67_02/lib/NEXT.pm" >0.67_02 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.67_01/lib/NEXT.pm" >0.67_01 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.67/lib/NEXT.pm" >0.67 (NEILB on 2016-07-30)</option> <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.66/lib/NEXT.pm" >0.66 (NEILB on 2016-07-28)</option> <option value="/release/NEILB/NEXT-0.69/diff/NEILB/NEXT-0.65_01/lib/NEXT.pm" >0.65_01 DEV (NEILB on 2016-07-20)</option> <option value="/release/NEILB/NEXT-0.69/diff/FLORA/NEXT-0.65/lib/NEXT.pm" >0.65 (FLORA on 2010-09-20)</option> <option value="/release/NEILB/NEXT-0.69/diff/FLORA/NEXT-0.64/lib/NEXT.pm" >0.64 (FLORA on 2009-06-08)</option> <option value="/release/NEILB/NEXT-0.69/diff/FLORA/NEXT-0.63/lib/NEXT.pm" >0.63 (FLORA on 2009-04-10)</option> <option value="/release/NEILB/NEXT-0.69/diff/FLORA/NEXT-0.62/lib/NEXT.pm" >0.62 (FLORA on 2009-04-08)</option> <option value="/release/NEILB/NEXT-0.69/diff/FLORA/NEXT-0.61/lib/NEXT.pm" >0.61 (FLORA on 2009-03-24)</option> <option value="/release/NEILB/NEXT-0.69/diff/DCONWAY/NEXT-0.60/lib/NEXT.pm" >0.60 (DCONWAY on 2003-08-13)</option> <option value="/release/NEILB/NEXT-0.69/diff/DCONWAY/NEXT-0.52/lib/NEXT.pm" >0.52 (DCONWAY on 2003-07-31)</option> <option value="/release/NEILB/NEXT-0.69/diff/DCONWAY/NEXT-0.51/lib/NEXT.pm" >0.51 (DCONWAY on 2003-07-30)</option> <option value="/release/NEILB/NEXT-0.69/diff/DCONWAY/NEXT-0.50/lib/NEXT.pm" >0.50 (DCONWAY on 2001-11-16)</option> <option value="/release/NEILB/NEXT-0.69/diff/DCONWAY/NEXT-0.02/lib/NEXT.pm" >0.02 (DCONWAY on 2001-09-02)</option> <option value="/release/NEILB/NEXT-0.69/diff/DCONWAY/NEXT-0.01/lib/NEXT.pm" >0.01 (DCONWAY on 2001-04-12)</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/overload" title="overload" class="ellipsis">overload</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><i class="ttip" title="dynamic_config enabled">and possibly others</i></li> <li> <hr> </li> <li> <a href="/module/NEXT/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=NEXT">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=NEXT">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/NEILB/NEXT-0.69/view/lib/NEXT.pm">This version</a> </li> <li> <a href="/pod/NEXT">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/NEILB" class="author-name">Neil Bowers</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/NEILB/NEXT-0.69/view/lib/NEXT.pm" >0.69 (NEILB on 2022-01-19)</option> <optgroup label="BackPAN">' <option value="/release/NEILB/NEXT-0.68/view/lib/NEXT.pm" >0.68 (NEILB on 2021-04-19)</option> <option value="/release/NEILB/NEXT-0.67_03/view/lib/NEXT.pm" >0.67_03 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.67_02/view/lib/NEXT.pm" >0.67_02 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.67_01/view/lib/NEXT.pm" >0.67_01 DEV (NEILB on 2021-04-18)</option> <option value="/release/NEILB/NEXT-0.67/view/lib/NEXT.pm" >0.67 (NEILB on 2016-07-30)</option> <option value="/release/NEILB/NEXT-0.66/view/lib/NEXT.pm" >0.66 (NEILB on 2016-07-28)</option> <option value="/release/NEILB/NEXT-0.65_01/view/lib/NEXT.pm" >0.65_01 DEV (NEILB on 2016-07-20)</option> <option value="/release/FLORA/NEXT-0.65/view/lib/NEXT.pm" >0.65 (FLORA on 2010-09-20)</option> <option value="/release/FLORA/NEXT-0.64/view/lib/NEXT.pm" >0.64 (FLORA on 2009-06-08)</option> <option value="/release/FLORA/NEXT-0.63/view/lib/NEXT.pm" >0.63 (FLORA on 2009-04-10)</option> <option value="/release/FLORA/NEXT-0.62/view/lib/NEXT.pm" >0.62 (FLORA on 2009-04-08)</option> <option value="/release/FLORA/NEXT-0.61/view/lib/NEXT.pm" >0.61 (FLORA on 2009-03-24)</option> <option value="/release/DCONWAY/NEXT-0.60/view/lib/NEXT.pm" >0.60 (DCONWAY on 2003-08-13)</option> <option value="/release/DCONWAY/NEXT-0.52/view/lib/NEXT.pm" >0.52 (DCONWAY on 2003-07-31)</option> <option value="/release/DCONWAY/NEXT-0.51/view/lib/NEXT.pm" >0.51 (DCONWAY on 2003-07-30)</option> <option value="/release/DCONWAY/NEXT-0.50/view/lib/NEXT.pm" >0.50 (DCONWAY on 2001-11-16)</option> <option value="/release/DCONWAY/NEXT-0.02/view/lib/NEXT.pm" >0.02 (DCONWAY on 2001-09-02)</option> <option value="/release/DCONWAY/NEXT-0.01/view/lib/NEXT.pm" >0.01 (DCONWAY on 2001-04-12)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/NEXT">NEXT-0.69</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; • 39 direct dependents &#10; • 118 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="NEXT-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="NEXT-0.69"> <input type="hidden" name="author" value="NEILB"> <input type="hidden" name="distribution" value="NEXT"> <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>NEXT</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="#Enforcing-redispatch">Enforcing redispatch</a></li> <li><a href="#Avoiding-repetitions">Avoiding repetitions</a></li> <li><a href="#Invoking-all-versions-of-a-method-with-a-single-call">Invoking all versions of a method with a single call</a></li> <li><a href="#Using-EVERY-methods">Using EVERY methods</a></li> </ul> </li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#BUGS-AND-IRRITATIONS">BUGS AND IRRITATIONS</a></li> <li><a href="#COPYRIGHT">COPYRIGHT</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>NEXT - Provide a pseudo-class NEXT (et al) that allows method redispatch</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>use NEXT; package P; sub P::method { print &quot;$_[0]: P method\n&quot;; $_[0]-&gt;NEXT::method() } sub P::DESTROY { print &quot;$_[0]: P dtor\n&quot;; $_[0]-&gt;NEXT::DESTROY() } package Q; use base qw( P ); sub Q::AUTOLOAD { print &quot;$_[0]: Q AUTOLOAD\n&quot;; $_[0]-&gt;NEXT::AUTOLOAD() } sub Q::DESTROY { print &quot;$_[0]: Q dtor\n&quot;; $_[0]-&gt;NEXT::DESTROY() } package R; sub R::method { print &quot;$_[0]: R method\n&quot;; $_[0]-&gt;NEXT::method() } sub R::AUTOLOAD { print &quot;$_[0]: R AUTOLOAD\n&quot;; $_[0]-&gt;NEXT::AUTOLOAD() } sub R::DESTROY { print &quot;$_[0]: R dtor\n&quot;; $_[0]-&gt;NEXT::DESTROY() } package S; use base qw( Q R ); sub S::method { print &quot;$_[0]: S method\n&quot;; $_[0]-&gt;NEXT::method() } sub S::AUTOLOAD { print &quot;$_[0]: S AUTOLOAD\n&quot;; $_[0]-&gt;NEXT::AUTOLOAD() } sub S::DESTROY { print &quot;$_[0]: S dtor\n&quot;; $_[0]-&gt;NEXT::DESTROY() } package main; my $obj = bless {}, &quot;S&quot;; $obj-&gt;method(); # Calls S::method, P::method, R::method $obj-&gt;missing_method(); # Calls S::AUTOLOAD, Q::AUTOLOAD, R::AUTOLOAD # Clean-up calls S::DESTROY, Q::DESTROY, P::DESTROY, R::DESTROY</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>The <code>NEXT</code> module adds a pseudoclass named <code>NEXT</code> to any program that uses it. If a method <code>m</code> calls <code>$self-&gt;NEXT::m()</code>, the call to <code>m</code> is redispatched as if the calling method had not originally been found.</p> <p><b>Note:</b> before using this module, you should look at <a href="https://metacpan.org/pod/mro#next::method">next::method</a> in the core <a href="/pod/mro">mro</a> module. <code>mro</code> has been a core module since Perl 5.9.5.</p> <p>In other words, a call to <code>$self-&gt;NEXT::m()</code> resumes the depth-first, left-to-right search of <code>$self</code>&#39;s class hierarchy that resulted in the original call to <code>m</code>.</p> <p>Note that this is not the same thing as <code>$self-&gt;SUPER::m()</code>, which begins a new dispatch that is restricted to searching the ancestors of the current class. <code>$self-&gt;NEXT::m()</code> can backtrack past the current class -- to look for a suitable method in other ancestors of <code>$self</code> -- whereas <code>$self-&gt;SUPER::m()</code> cannot.</p> <p>A typical use would be in the destructors of a class hierarchy, as illustrated in the SYNOPSIS above. Each class in the hierarchy has a DESTROY method that performs some class-specific action and then redispatches the call up the hierarchy. As a result, when an object of class S is destroyed, the destructors of <i>all</i> its parent classes are called (in depth-first, left-to-right order).</p> <p>Another typical use of redispatch would be in <code>AUTOLOAD</code>&#39;ed methods. If such a method determined that it was not able to handle a particular call, it might choose to redispatch that call, in the hope that some other <code>AUTOLOAD</code> (above it, or to its left) might do better.</p> <p>By default, if a redispatch attempt fails to find another method elsewhere in the objects class hierarchy, it quietly gives up and does nothing (but see <a href="#Enforcing-redispatch">&quot;Enforcing redispatch&quot;</a>). This gracious acquiescence is also unlike the (generally annoying) behaviour of <code>SUPER</code>, which throws an exception if it cannot redispatch.</p> <p>Note that it is a fatal error for any method (including <code>AUTOLOAD</code>) to attempt to redispatch any method that does not have the same name. For example:</p> <pre><code>sub S::oops { print &quot;oops!\n&quot;; $_[0]-&gt;NEXT::other_method() }</code></pre> <h2 id="Enforcing-redispatch"><a id="Enforcing"></a>Enforcing redispatch</h2> <p>It is possible to make <code>NEXT</code> redispatch more demandingly (i.e. like <code>SUPER</code> does), so that the redispatch throws an exception if it cannot find a &quot;next&quot; method to call.</p> <p>To do this, simple invoke the redispatch as:</p> <pre><code>$self-&gt;NEXT::ACTUAL::method();</code></pre> <p>rather than:</p> <pre><code>$self-&gt;NEXT::method();</code></pre> <p>The <code>ACTUAL</code> tells <code>NEXT</code> that there must actually be a next method to call, or it should throw an exception.</p> <p><code>NEXT::ACTUAL</code> is most commonly used in <code>AUTOLOAD</code> methods, as a means to decline an <code>AUTOLOAD</code> request, but preserve the normal exception-on-failure semantics:</p> <pre><code>sub AUTOLOAD { if ($AUTOLOAD =~ /foo|bar/) { # handle here } else { # try elsewhere shift()-&gt;NEXT::ACTUAL::AUTOLOAD(@_); } }</code></pre> <p>By using <code>NEXT::ACTUAL</code>, if there is no other <code>AUTOLOAD</code> to handle the method call, an exception will be thrown (as usually happens in the absence of a suitable <code>AUTOLOAD</code>).</p> <h2 id="Avoiding-repetitions"><a id="Avoiding"></a>Avoiding repetitions</h2> <p>If <code>NEXT</code> redispatching is used in the methods of a &quot;diamond&quot; class hierarchy:</p> <pre><code># A B # / \ / # C D # \ / # E use NEXT; package A; sub foo { print &quot;called A::foo\n&quot;; shift-&gt;NEXT::foo() } package B; sub foo { print &quot;called B::foo\n&quot;; shift-&gt;NEXT::foo() } package C; @ISA = qw( A ); sub foo { print &quot;called C::foo\n&quot;; shift-&gt;NEXT::foo() } package D; @ISA = qw(A B); sub foo { print &quot;called D::foo\n&quot;; shift-&gt;NEXT::foo() } package E; @ISA = qw(C D); sub foo { print &quot;called E::foo\n&quot;; shift-&gt;NEXT::foo() } E-&gt;foo();</code></pre> <p>then derived classes may (re-)inherit base-class methods through two or more distinct paths (e.g. in the way <code>E</code> inherits <code>A::foo</code> twice -- through <code>C</code> and <code>D</code>). In such cases, a sequence of <code>NEXT</code> redispatches will invoke the multiply inherited method as many times as it is inherited. For example, the above code prints:</p> <pre><code>called E::foo called C::foo called A::foo called D::foo called A::foo called B::foo</code></pre> <p>(i.e. <code>A::foo</code> is called twice).</p> <p>In some cases this <i>may</i> be the desired effect within a diamond hierarchy, but in others (e.g. for destructors) it may be more appropriate to call each method only once during a sequence of redispatches.</p> <p>To cover such cases, you can redispatch methods via:</p> <pre><code>$self-&gt;NEXT::DISTINCT::method();</code></pre> <p>rather than:</p> <pre><code>$self-&gt;NEXT::method();</code></pre> <p>This causes the redispatcher to only visit each distinct <code>method</code> method once. That is, to skip any classes in the hierarchy that it has already visited during redispatch. So, for example, if the previous example were rewritten:</p> <pre><code>package A; sub foo { print &quot;called A::foo\n&quot;; shift-&gt;NEXT::DISTINCT::foo() } package B; sub foo { print &quot;called B::foo\n&quot;; shift-&gt;NEXT::DISTINCT::foo() } package C; @ISA = qw( A ); sub foo { print &quot;called C::foo\n&quot;; shift-&gt;NEXT::DISTINCT::foo() } package D; @ISA = qw(A B); sub foo { print &quot;called D::foo\n&quot;; shift-&gt;NEXT::DISTINCT::foo() } package E; @ISA = qw(C D); sub foo { print &quot;called E::foo\n&quot;; shift-&gt;NEXT::DISTINCT::foo() } E-&gt;foo();</code></pre> <p>then it would print:</p> <pre><code>called E::foo called C::foo called A::foo called D::foo called B::foo</code></pre> <p>and omit the second call to <code>A::foo</code> (since it would not be distinct from the first call to <code>A::foo</code>).</p> <p>Note that you can also use:</p> <pre><code>$self-&gt;NEXT::DISTINCT::ACTUAL::method();</code></pre> <p>or:</p> <pre><code>$self-&gt;NEXT::ACTUAL::DISTINCT::method();</code></pre> <p>to get both unique invocation <i>and</i> exception-on-failure.</p> <p>Note that, for historical compatibility, you can also use <code>NEXT::UNSEEN</code> instead of <code>NEXT::DISTINCT</code>.</p> <h2 id="Invoking-all-versions-of-a-method-with-a-single-call"><a id="Invoking"></a>Invoking all versions of a method with a single call</h2> <p>Yet another pseudo-class that <code>NEXT</code> provides is <code>EVERY</code>. Its behaviour is considerably simpler than that of the <code>NEXT</code> family. A call to:</p> <pre><code>$obj-&gt;EVERY::foo();</code></pre> <p>calls <i>every</i> method named <code>foo</code> that the object in <code>$obj</code> has inherited. That is:</p> <pre><code>use NEXT; package A; @ISA = qw(B D X); sub foo { print &quot;A::foo &quot; } package B; @ISA = qw(D X); sub foo { print &quot;B::foo &quot; } package X; @ISA = qw(D); sub foo { print &quot;X::foo &quot; } package D; sub foo { print &quot;D::foo &quot; } package main; my $obj = bless {}, &#39;A&#39;; $obj-&gt;EVERY::foo(); # prints&quot; A::foo B::foo X::foo D::foo</code></pre> <p>Prefixing a method call with <code>EVERY::</code> causes every method in the object&#39;s hierarchy with that name to be invoked. As the above example illustrates, they are not called in Perl&#39;s usual &quot;left-most-depth-first&quot; order. Instead, they are called &quot;breadth-first-dependency-wise&quot;.</p> <p>That means that the inheritance tree of the object is traversed breadth-first and the resulting order of classes is used as the sequence in which methods are called. However, that sequence is modified by imposing a rule that the appropriate method of a derived class must be called before the same method of any ancestral class. That&#39;s why, in the above example, <code>X::foo</code> is called before <code>D::foo</code>, even though <code>D</code> comes before <code>X</code> in <code>@B::ISA</code>.</p> <p>In general, there&#39;s no need to worry about the order of calls. They will be left-to-right, breadth-first, most-derived-first. This works perfectly for most inherited methods (including destructors), but is inappropriate for some kinds of methods (such as constructors, cloners, debuggers, and initializers) where it&#39;s more appropriate that the least-derived methods be called first (as more-derived methods may rely on the behaviour of their &quot;ancestors&quot;). In that case, instead of using the <code>EVERY</code> pseudo-class:</p> <pre><code>$obj-&gt;EVERY::foo(); # prints&quot; A::foo B::foo X::foo D::foo </code></pre> <p>you can use the <code>EVERY::LAST</code> pseudo-class:</p> <pre><code>$obj-&gt;EVERY::LAST::foo(); # prints&quot; D::foo X::foo B::foo A::foo </code></pre> <p>which reverses the order of method call.</p> <p>Whichever version is used, the actual methods are called in the same context (list, scalar, or void) as the original call via <code>EVERY</code>, and return:</p> <ul> <li><p>A hash of array references in list context. Each entry of the hash has the fully qualified method name as its key and a reference to an array containing the method&#39;s list-context return values as its value.</p> </li> <li><p>A reference to a hash of scalar values in scalar context. Each entry of the hash has the fully qualified method name as its key and the method&#39;s scalar-context return values as its value.</p> </li> <li><p>Nothing in void context (obviously).</p> </li> </ul> <h2 id="Using-EVERY-methods"><a id="Using"></a>Using <code>EVERY</code> methods</h2> <p>The typical way to use an <code>EVERY</code> call is to wrap it in another base method, that all classes inherit. For example, to ensure that every destructor an object inherits is actually called (as opposed to just the left-most-depth-first-est one):</p> <pre><code>package Base; sub DESTROY { $_[0]-&gt;EVERY::Destroy } package Derived1; use base &#39;Base&#39;; sub Destroy {...} package Derived2; use base &#39;Base&#39;, &#39;Derived1&#39;; sub Destroy {...}</code></pre> <p>et cetera. Every derived class than needs its own clean-up behaviour simply adds its own <code>Destroy</code> method (<i>not</i> a <code>DESTROY</code> method), which the call to <code>EVERY::LAST::Destroy</code> in the inherited destructor then correctly picks up.</p> <p>Likewise, to create a class hierarchy in which every initializer inherited by a new object is invoked:</p> <pre><code> package Base; sub new { my ($class, %args) = @_; my $obj = bless {}, $class; $obj-&gt;EVERY::LAST::Init(\%args); } package Derived1; use base &#39;Base&#39;; sub Init { my ($argsref) = @_; ... } package Derived2; use base &#39;Base&#39;, &#39;Derived1&#39;; sub Init { my ($argsref) = @_; ... }</code></pre> <p>et cetera. Every derived class than needs some additional initialization behaviour simply adds its own <code>Init</code> method (<i>not</i> a <code>new</code> method), which the call to <code>EVERY::LAST::Init</code> in the inherited constructor then correctly picks up.</p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <p><a href="/pod/mro">mro</a> (in particular <a href="https://metacpan.org/pod/mro#next::method">next::method</a>), which has been a core module since Perl 5.9.5.</p> <h1 id="AUTHOR">AUTHOR</h1> <p>Damian Conway (damian@conway.org)</p> <h1 id="BUGS-AND-IRRITATIONS"><a id="BUGS"></a>BUGS AND IRRITATIONS</h1> <p>Because it&#39;s a module, not an integral part of the interpreter, <code>NEXT</code> has to guess where the surrounding call was found in the method look-up sequence. In the presence of diamond inheritance patterns it occasionally guesses wrong.</p> <p>It&#39;s also too slow (despite caching).</p> <p>Comment, suggestions, and patches welcome.</p> <h1 id="COPYRIGHT">COPYRIGHT</h1> <pre><code>Copyright (c) 2000-2001, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.</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 NEXT, 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 NEXT</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install NEXT</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