in reply to Cross reference between two classes and FIELDS
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 | |
by sgifford (Prior) on Sep 27, 2006 at 20:07 UTC |