in reply to Cross reference between two classes and FIELDS

Hi nite_man,

If I use class names like ClassA and ClassB (because B is a system class), everything seems to work OK for me. I have had similar problems to those you describe when I tried to put multiple packages in the same file with nontrivial inheritance relationships.

Here's the code I tested:

package ClassA; use strict; use base qw(fields); use fields qw(id name); sub new { my $class = shift; $class->SUPER::new(); } sub getclass { my $self = shift; return ref($self); } 1;
package ClassB; use strict; use base qw(ClassA); use fields qw(addr phone city); use ClassC; sub addC { my $self = shift; $self->{c} = ClassC->new(); } 1;
package ClassC; use strict; use base qw(ClassA); use fields qw(model type); sub addB { my $self = shift; $self->{b} = ClassB->new(); } 1;
#!/usr/bin/perl -l # Test program use ClassA; use ClassB; use ClassC; my $a = ClassA->new(); my $b = ClassB->new(); my $c = ClassC->new(); print $a->getclass(); print $b->getclass(); print $c->getclass(); $b->{name} = 'bee'; print $b->{name}; $c->{name} = 'see'; print $c->{name}; $b->{city} = 'wok'; print $b->{city}; $c->{model} = 't'; print $c->{model};

Replies are listed 'Best First'.
Re^2: Cross reference between two classes and FIELDS
by nite_man (Deacon) on Sep 26, 2006 at 15:47 UTC
    Hi sgifford, Probably you're right. The problem with nontrivial inheritance relationships. But how to avoid it (to rebuild whole application is not appropriate way :))?

    ---
    Michael Stepanov aka nite_man

    It's only my opinion and it doesn't have pretensions of absoluteness!

      I only had this problem when I put multiple classes with inheritance relationships in the same file; putting each class in its own file solved the problem.