SPUG: OO Perl object backrefrence question

Peter Darley pdarley at kinesis-cem.com
Fri Sep 6 10:50:41 CDT 2002


Ryan,
	Thanks!  That's exactly what I was looking for.
Thanks,
Peter Darley

-----Original Message-----
From: owner-spug-list at pm.org [mailto:owner-spug-list at pm.org]On Behalf Of
Parr, Ryan
Sent: Friday, September 06, 2002 8:24 AM
To: SPUG
Subject: RE: SPUG: OO Perl object backrefrence question


There's an article by Matt Sergeant on Perl.com right now that covers
exactly this.

http://www.perl.com/pub/a/2002/08/07/proxyobject.html

Basically it shows how to pass a parent object to a child without creating a
circular reference.

-- Ryan

-----Original Message-----
From: Peter Darley [mailto:pdarley at kinesis-cem.com]
Sent: Friday, September 06, 2002 7:31 AM
To: SPUG
Subject: SPUG: OO Perl object backrefrence question


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

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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