Perl: Important statements for perl inheritance

From the earlier post you might have learned how to create module files in perl and how does one package inherits from another.

Here is a list of important points to remember.

1) use <parent package name>

2) our @ISA = qw (parent package name)

3) If you are overriding any existing method from parent class then you first need to declare that method with same name and use keyword SUPER. SUPER tells the perl interpreter to locate the method from parent class.

syntax for using SUPER is :

$self = $class ->SUPER::<name of method>(arguments in original method)

Note: If the method from parent class is having 2 arguments then you have to include 2 arguments and not more or less than that. You can add more arguments or assign any value to argument, in the child class.

This is called method overriding in perl.

4) In main executable file you should use only child package, which will inherit all the methods from parent package or packages.

Tags: , , , , , , ,

Leave a comment