NAME
SUPER - Control superclass method despatch
SYNOPSIS
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 just, Ruby-style:
sub my_method {
my $self = shift;
if ($want_to_deal_with_this) { ... }
else { super }
}
DESCRIPTION
When subclassing a class, you occasionally want to despatch 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 with its Ruby equivalent:
super;
This module provides that equivalent, along with the universal method super
to determine one's own superclass. This allows you do to things like
goto &{$_[0]->super("my_method")};
if you don't like wasting precious stack frames. (And since super
returns a coderef, much like "can" in UNIVERSAL, this doesn't break use strict 'refs'
.)
NOTES
It has been pointed out that using super
doesn't let you pass alternate arguments to your superclass's method. If you want to pass different arguments, well, don't use super
then. D'oh.
This module does a small amount of Deep Magic to find out what arguments the method calling super
itself had, and this may confuse things like Devel::Cover
.
AUTHOR
Simon Cozens, simon@cpan.org
LICENSE
This silly little module may be distributed under the same terms as Perl itself.