views:

104

answers:

5

Alrighty, coding in Perl and just had a quick question. I have class created called SubtitleSite which is basically an abstraction, and a class called podnapisi that inherits SubtitleSite like this:

@ISA = qw(SubtitleSite);

My question is, do I have to use:

use SubtitleSite;

in order to have access to all the methods in SubtitleSite?

+3  A: 
Dana
+2  A: 

YES.

Otherwise the symbols defined in SubtitleSite are undefined in podnapisi.

lexu
+11  A: 

Yes, but most of the time you're better off not messing with @ISA directly. Just use parent qw(SubtitlesSite);, it will load SubtilteSite for you and add it to @ISA.

Ronald Blaschke
Note that `parent` did not become a core module until 5.10. If you're using an older perl you'll either need to use the older `base` pragma or install `parent`.
friedo
A: 

In order to access the methods, you'd either have to inherit from it, or delegate to an object of it's type.

Geo
A: 

If you are constructing an object in your child class, you can just call methods on yourself and they will be found through the magic of inheritance (see perldoc perlobj for more about SUPER):

sub foo
{
    my $this = shift;
    $this->method_on_parent;  # this works!
    $this->SUPER::foo;        # this works too
}

However if these classes are only library functions that don't use OO, you have to tell Perl explicitly where to find the function:

ParentClass::function;    # use the class name explicitly
Ether
Attn downvoter: incorrect manual reference corrected.
Ether