Movatterモバイル変換


[0]ホーム

URL:


 / 
SUPER-1.20190531
River stage three • 17 direct dependents • 278 total dependents
/SUPER

NAME

SUPER - control superclass method dispatch

SYNOPSIS

Find the parent method that would run if this weren't here:

sub my_method{    my $self = shift;    my $super = $self->super('my_method'); # Who's your daddy?    if ($want_to_deal_with_this)    {        # ...    }    else    {        $super->($self, @_)    }}

Or Ruby-style:

sub my_method{    my $self = shift;    if ($want_to_deal_with_this)    {        # ...    }    else    {        super;    }}

Or call the super method manually, with respect to inheritance, and passing different arguments:

sub my_method{    my $self = shift;    # parent handles args backwardly    $self->SUPER( reverse @_ );}

DESCRIPTION

When subclassing a class, you occasionally want to dispatch control to the superclass -- at least conditionally and temporarily. The Perl syntax for calling your superclass is ugly and unwieldy:

$self->SUPER::method(@_);

especially when compared to its Ruby equivalent:

super;

It's even worse in that the normal Perl redispatch mechanism only dispatches to the parent of the class containing the methodat compile time. That doesn't work very well for mixins and roles.

This module provides nicer equivalents, along with the universal methodsuper to determine a class' own superclass. This allows you to do things such as:

goto &{$_[0]->super('my_method')};

if you don't like wasting precious stack frames.

If you are using roles or mixins or otherwise pulling in methods from other packages that need to dispatch to their super methods, or if you want to pass different arguments to the super method, use theSUPER() method:

$self->SUPER( qw( other arguments here ) );

FUNCTIONS and METHODS

This module provides the following functions and methods:

super()

This function calls the super method of the currently-executing method, no matter where the super method is in the hierarchy.

This takes no arguments; it passes the same arguments passed to the currently-executing method.

The module exports this function by default.

Note: youmust have the appropriatepackage declaration in place for this to work. That is, you must havecompiled the method in which you use this function in the package from which you want to use it. Them's the breaks with Perl 5.

find_parent( $class, $method, $prune, $invocant )

Attempts to find a parent implementation of$method starting with$class. If you pass$prune, it will not ignore the method found in that package, if it exists there. Pass$invocant if the object itself might have a different idea of its parents.

The module does not export this function by default. Call it directly.

get_all_parents( $invocant, $class )

Returns all of the parents for the$invocant, if it supports the__get_parents() method or the contents of@ISA for$class. You probably oughtn't call this on your own.

SUPER()

Calls the super method of the currently-executing method. Youcan pass arguments. This is a method.

NOTES

Beware: if you do weird things with code generation, be sure toname your anonymous subroutines. SeePerl Hacks #57.

Usingsuper doesn't let you pass alternate arguments to your superclass's method. If you want to pass different arguments, useSUPER instead. D'oh.

This module does a small amount of Deep Magic to find the arguments of methodcallingsuper() itself. This may confuse tools such asDevel::Cover.

In your own code, if you do complicated things with proxy objects and the like, define__get_parents() to return a list of all parents of the object to which you really want to dispatch.

AUTHOR

Created by Simon Cozens,simon@cpan.org. Copyright (c) 2003 Simon Cozens.

Maintained by chromatic, <chromatic at wgz dot org> after version 1.01. Copyright (c) 2004-2019 chromatic.

Thanks to Joshua ben Jore for bug reports and suggestions.

LICENSE

You may use and distribute this silly little module under the same terms as Perl itself.

Module Install Instructions

To install SUPER, copy and paste the appropriate command in to your terminal.

cpanm

cpanm SUPER

CPAN shell

perl -MCPAN -e shellinstall SUPER

For more information on module installation, please visitthe detailed CPAN module installation guide.

Keyboard Shortcuts

Global
sFocus search bar
?Bring up this help dialog
GitHub
gpGo to pull requests
gigo to github issues (only if github is preferred repository)
POD
gaGo to author
gcGo to changes
giGo to issues
gdGo to dist
grGo to repository/SCM
gsGo to source
gbGo to file browse
Search terms
module: (e.g.module:Plugin)
distribution: (e.g.distribution:Dancer auth)
author: (e.g.author:SONGMU Redis)
version: (e.g.version:1.00)

[8]ページ先頭

©2009-2025 Movatter.jp