以下の例は、スーパークラスのメソッドをオーバライドし、オーバライドされた 後でそのメソッドを呼び出す方法を示します。`Foo::Inherit' クラスを使っ て、オーバライドされたスーパークラスのメソッドが、実際には、どこで定義さ れているか知らなくても、そのメソッドを呼び出せるようにしています。
package Buz;
sub goo { print "here's the goo\n" }
package Bar; @ISA = qw( Buz );
sub google { print "google here\n" }
package Baz;
sub mumble { print "mumbling\n" }
package Foo;
@ISA = qw( Bar Baz );
@Foo::Inherit::ISA = @ISA; # オーバライドされたメソッドのアクセス
sub new { bless [] }
sub grr { print "grumble\n" }
sub goo {
my $self = shift;
$self->Foo::Inherit::goo();
}
sub mumble {
my $self = shift;
$self->Foo::Inherit::mumble();
}
sub google {
my $self = shift;
$self->Foo::Inherit::google();
}
package main;
$foo = new Foo;
$foo->mumble;
$foo->grr;
$foo->goo;
$foo->google;
Go to the first, previous, next, last section, table of contents.