Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TheNomad (7014)

  (email not shown publicly)

Journal of TheNomad (7014)

Thursday June 29, 2006
08:56 AM

Odd inheritance behaviour

[ #30090 ]

I've got an application where I have an abstract class A, B inherits from A, and C inherits from B. Class P has-a C.

Class A uses 'base' Class::Accessor::Fast to create accessors. All classes A, B and C do __PACKAGE__->mk_accessors, to make their accessors.

The test suite ran fine over classes A, B and C. However, when I came to run the tests for P, perl would complain 'can't find package method mk_accessors in class C'.

If I added 'use base 'Class::Accessor' to C, the tests would run fine. But this violated the principle that C should only inherit from B.

I guessed that somehow at compile-time perl wasn't running all the way up the class hierarchy when importing package C. I figured that delaying the import until run-time would fix this problem.

I changed 'use C' to 'require C' and the problem was solved, with the tests for class P running fine.

But the question remains, why is perl (5.8.8) not running all the way up the class hierarchy when it imports classes? Or is it something to do with the implementation of Class::Accessor::Fast?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • ...without seeing what you've actually done. Can you reproduce it with a small set of code and show that?
    Ordinary morality is for ordinary people. -- Aleister Crowley
    • Sure...Each of these are in a seperate file:

      package A;
      use base 'Class::Accessor::Fast';

      package B;
      use base 'A';

      package C;
      use base 'B';

      package P;

      use C;

      In the test suite:

      use_ok('C') .... ok

      In a seperate test file:


      Fails 'Can't find package method mk_accessors via package 'C'.

      On the other hand if I change P from 'use P' to 'require P' it works.