ido50 has asked for the wisdom of the Perl Monks concerning the following question:

Hi there!
I'm writing a CGI/Perl program, object-oriented style. I have a class, let's say it's called A::B. I also have an A::B::C class. I want A::B::C to inherit from A::B.
The A::B::C class looks like this:

package A::B::C; use lib "$A::PATH/cgi-bin/A"; use A::B; @ISA = qw/A::B/; use strict; bla bla bla...

Anyway, the A::B class has a new method, A::B::C doesn't. When I try to invoke the new method using the A::B::C class, I get a message that the new method cannot be located on that class. Why doesn't the A::B::C class inherit from A::B ??
Should mention both classes are modules.

Thanks,
Ido.

-------------------------
Live fat, die young

Replies are listed 'Best First'.
Re: Class doesn't inherit
by Anomynous Monk (Scribe) on Mar 17, 2004 at 19:48 UTC
    Can you show how you are doing the use A::B::C and how you are calling new?

    And using strict and warnings is always a good thing.

      Well, I got it, I didn't use A::B::C before calling the new method. Thanks for pointing my attention to it.
      -------------------------
      Live fat, die young
Re: Class doesn't inherit
by etcshadow (Priest) on Mar 17, 2004 at 20:04 UTC
    Another thing that may not be causing you trouble right now... but you should wrap your @ISA initialization in a BEGIN block. Otherwise you could unexpectadly run into trouble later (if you get a convoluted use order).
    ------------ :Wq Not an editor command: Wq
      insert obligatory reference to "use base" here

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        Yes, absolutely, "use base" addresses this problem... when it works. Older versions of use base (like the version that come with 5.005_03, which is what I'm still stuck on) do not work properly, unfortunately.

        Granted, I'm not griping, because it looks like it's since been fixed... but also:

        BEGIN { @ISA = qw( Foo Bar ) }
        is really not that hard, either.
        ------------ :Wq Not an editor command: Wq
      Okay thanks.
      -------------------------
      Live fat, die young