Wxperl is a pure oo GUI library. Today, when I looked at its example, I also tried different inheritance methods.
This is used in hello. pl of wxperl:
Use vars QW (@ ISA );
@ ISA = QW (wx: APP );
I checked the use vars Pragma in programming Perl and found that this usage is already in some degree.
The code above is equivalent:
Our (@ ISA) = QW (wx: APP );
They define a global variable for a package. Note that do not use them together, that is, do not
Use use vars and our at the same time for @ ISA in the code. (When more than one package is defined in a file)
In addition to the two methods, you can also use:
Use base QW (wx: APP );
This code is equivalent:
Begin {
Require wx: app; # note that the raw text is used here. For details, refer to the introduction of require.
Push @ Isa, QW (wx: APP );
}
We also found a small problem, using use base QW (wx: APP );
The parent class must end with 1; while the other two methods may also be OK.
This may be the reason for require.
The classes (packages) listed in the @ ISA array indicate the parent class or base class of the current class ). It is the inheritance Method on which Perl depends. @ ISA array contains a list of classes (packages). When Perl cannot find the required method in the current class (package), it searches for Classes listed in this array. If it still cannot be found, Perl will search for and call the autoload function. If it still cannot be found, Perl will perform the final search in the predefined universal package. The global base class of all packages in the universal class is also the class at the top of the class inheritance mechanism.
The @ ISA array is not searched during a normal subroutine call. However, if you call a subroutine by calling the method syntax, the program will search for the @ ISA array.
If a Perl package does not have a new function, but you need to call the functions in this package, you can add the function of this package to ISA using the following method. Then add & to the function in another package &.
Require exporter;
Use vars ('@ ISA ');
@ ISA = QW (exporter );
Our @ export = QW (function name );
The second method is to add the use package path name at the beginning, and then use the Class Name> package path name: function name to reference the function under the package ..