our @ISA = "Critter";
In which condition will I use @ISA
?
and why our @ISA
?.
The can() method accepts the method's name as a string. It returns a reference to the existing function that implements this method or else it returns a false value. This method can be called on a class, object, or a package.
Object Basics The object is stored as a reference in a scalar variable. Because a scalar only contains a reference to the object, the same scalar can hold different objects in different classes. A class within Perl is a package that contains the corresponding methods required to create and manipulate objects.
@INC is a special Perl variable that is the equivalent to the shell's PATH variable. Whereas PATH contains a list of directories to search for executables, @INC contains a list of directories from which Perl modules and libraries can be loaded.
To extend Mat's comment, stuff like this is extensively documented in the perldocs
.
Regarding @ISA
, here's what it says:
A Class is Simply a Package
...
Each package contains a special array called
@ISA
. The@ISA
array contains a list of that class's parent classes, if any. This array is examined when Perl does method resolution, which we will cover later.It is possible to manually set
@ISA
, and you may see this in older Perl code. Much older code also uses thebase
pragma. For new code, we recommend that you use theparent
pragma to declare your parents. This pragma will take care of setting@ISA
. It will also load the parent classes and make sure that the package doesn't inherit from itself.However the parent classes are set, the package's
@ISA
variable will contain a list of those parents. This is simply a list of scalars, each of which is a string that corresponds to a package name.
our
and @ISA
go hand in hand because @ISA
is expected to be a package variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With