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

Hi folks. This is a basic OO Perl question, but nonetheless it currently has me stumped.

I have the following relationship between some classes:

Foo::TestScript.pm: use base qw(Test::Class); use Test::More; # both CPAN modules myTest.pm: use base qw(Foo::TestScript);

So myTest ISA Foo::TestScript and Foo::TestScript is using Test::More. Now, I expect to be able to call methods from Test::More (for example, is() and isnt()) from myTest.pm. But when I do I get an error that &myTest::is() is undefined.

If I "use Test::More" directly from myTest.pm, I can call the methods just fine. However, I would prefer to inherit this functionality via the parent class, TestScript.

So what am I missing about subclassing here? Much thanks.

-zaven

Replies are listed 'Best First'.
Re: Accessing the namespace of a class's grandparent
by rhesa (Vicar) on Dec 17, 2006 at 02:15 UTC
    The Test::More functions are not object methods, so you won't be able to inherit them. Since Test::More only exports functions, you'll have to use it in all your subclasses. See Test::Class, section TEST CLASSES, for confirmation.