Deferring the load until runtime with "require" seems to work, though it kinda surprises me that the calls to OtherClass->method don't trigger a warning when OtherClass isn't known about at compile time. On Wed, Aug 4, 2010 at 8:21 PM, Mark J. Reed <markjreed@gmail.com> wrote: > Dumb question maybe, but if I have two classes which need to call > methods on each other's objects, how can I define them without getting > 'redefined subroutine' warnings (and possibly assorted other > circular-reference problems)? > > Here's the basic model: > > package Parent; > use base ModelObject; > use Child; > sub children { > my $self = shift; > unless ($self->{_children}) { > foreach my $child_id (@{$self->{children}}) { > push @{$self-{_children}}, Child->lookup($child_id); > } > } > return $self->{_children}; > } > 1; > > package Child; > use base ModelObject; > use Parent; > sub parent { > my $self = shift; > return $self->{_parent} ||= Parent->lookup($self->{_parent_id}); > } > 1; > > Any suggestions? > -- Mark J. Reed <markjreed@gmail.com>Thread Previous