简体   繁体   中英

what is the difference between parent and @ISA?

both parent and @ISA doing same working, what is use of parent and @ISA accordingly.

package Baz;
    use parent qw(Foo Bar);

or

package Baz;
    BEGIN 
    {
        require Foo;
        require Bar;
        push @ISA, qw(Foo Bar);
    }

use parent is simply a concise way of doing a require and pushing the package name onto @ISA in one statement. It happens at compile time instead of a simple our @ISA = qw/ Foo Bar / which is done at run time, and means you have to code the package name only once which may reduce errors. It will also raise a warning if a package tries to inherit from a package of the same name, which would be useless and could cause an infinite inheritance loop.

In short, use parent is a more concise and easy way to get everything right.

parent is syntactic sugar to set a package's @ISA variable and automatically load its superclasses at compile time. As the parent documentation states, there is no functional difference between the two code blocks in the OP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM