You want the "c3" method resolution order. There is builtin support for this activated using use mro qw( c3 );. The module also provides next::method and maybe::next::method as alternatives to SUPER::.
use strict; use warnings; use feature qw( say ); { package ClsA; use mro 'c3'; sub foo { say __PACKAGE__; } } { package ClsB1; use mro 'c3'; our @ISA = qw( ClsA ); } { package ClsB2; use mro 'c3'; our @ISA = qw( ClsA ); sub foo { say __PACKAGE__; $_[0]->maybe::next::method() } } { package ClsB3; use mro 'c3'; our @ISA = qw( ClsA ); sub foo { say __PACKAGE__; $_[0]->maybe::next::method() } } { package ClsD; use mro 'c3'; our @ISA = qw( ClsB1 ClsB2 ClsB3 ); } ClsD->foo(); say "--"; ClsB2->foo();
ClsB2 ClsB3 ClsA -- ClsB2 ClsA
Update: Added code example and then improved it.
In reply to Re: Referring SUPER to superclass of object
by ikegami
in thread Referring SUPER to superclass of object
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |