SPUG: OO Perl object backrefrence question

Peter Darley pdarley at kinesis-cem.com
Fri Sep 6 09:30:39 CDT 2002


Friends,
	Another stupid question...

	I'm working on building a series of objects in a hierarchy that represents
a survey.  The survey object will hold page objects which will hold
questions object, etc.
	I'm wondering if there is a standard way for an object to know what it's
parent object is so I can pull properties from the parent instead of storing
it in each child object.  So, I want to be able to do something like
$self->Parent->ClientName to get the client name of the survey a page object
is part of.
	There are two ways that I can see of doing this, but they're both not
great.  The first would be to give the child a reference to the parent
object to store in a parent property, but this has problems with circular
references, and I'd probably have to do my own garbage collection.
	The other is to pass a string containing the name of the variable
containing the parent object (i.e. "$Main::MySurvey") then use "no strict
'refs'; $$Parent->whatever()" to de-reference it when it needs to be used.
This would keep garbage collection working, but wouldn't, I believe, be
storable, because the name would likely be different next time the script is
executed.
	Anyway, I was hoping that in addition to the normal messages letting me
know that this is all a bad thing to do someone might have some advise on
setting my objects up like this. :)

Thanks,
Peter Darley


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list