Thanks everybody pointing out that B is an internal Perl namespace. Duh! I will refrain from comment on whoever made that choice ...

In addition, I realized that the order in which 'use' and 'use fields' statements are made is very much significant; if one gets it wrong, mysterious things happen and no error messages are printed. My real code (not the snippet I sent) had something like this:

-- AA.pm --
package AA;
...

-- BB.pm --
package BB;
use AA;
use CC;
use base qw( AA );
use fields qw(  b1 b2 );
...

-- CC.pm --
package CC;
use BB;
use base qw( BB );
...

My class BB imports CC because under one of its methods creates instances of CC (which is supposed to be a subclass of BB). But because I stated
    'use CC'
before
    'use base'
    'use fields'
my file CC.pm would get read before BB was declared to be a child of AA, and thus would never inherit the fields from AA or BB.

The correct sequence is this:

-- AA.pm --
package AA;
...

-- BB.pm --
package BB;
use AA;
use base qw( AA );
use fields qw(  b1 b2 );
use CC; # <- after the 'use base' and 'use fields' statements
...

-- CC.pm --
package CC;
use BB;
use base qw( BB );
...



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to