use base somemodule;
# 相当于以下两句的结合:
BEGIN{
use somemodule ();
push @ISA, qw(somemodule);
}
# 也可以同时 use base 两个或者两个以上的模块,即多继承,例如:
use base qw(Foo Bar);
BEGIN {
use Foo ();
use Bar ();
push @ISA, qw(Foo Bar);
}
Perl
里 类方法通过@ISA
数组继承,这个数组里面包含其他包(类)的名字,变量的继承必须明确设定。- 多继承就是这个
@ISA
数组包含多个类(包)名字。 - 通过
@ISA
只能继承方法,不能继承数据。
参考文献
---------------------
Author: Frytea
Title: Perl 面向对象之基类(use base)
Link: https://blog.frytea.com/archives/562/
Copyright: This work by TL-Song is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.