logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: [Boston.pm] overriding instance methods, dynamic package namespaces: msg#00035

Subject: Re: [Boston.pm] overriding instance methods, dynamic package namespaces
>>>>> "TM" == Tom Metro <pm-5a1Jt6qxUNc@xxxxxxxxxxxxxxxx> writes:
  TM> Isn't there also a potential problem if the if something upstream of the 
  TM> reblessing saves a reference to the object, or is this true:

  TM>    use Scalar::Util 'refaddr';
  TM>    my $obj = {};
  TM>    my $before = refaddr($obj);
  TM>    my $newobj = bless($obj, 'foo');
  TM>    print "true\n" if $before eq refaddr($newobj);

  TM> Perl says it is. Makes sense, as although bless returns an object, it 
  TM> shouldn't create a new one.

as damian says, bless actually blesses the referenent, not the
reference. the underlying anon hash has 'foo' put into its 'bless'
slot. refs only point to the underlying thing which has the data and the
bless value. so reblessing will cause all refs (actually nothing happens
to the refs) to see the new blessed class. a ref only really has a
pointer to the referent which has the data, type and bless value (and
ref counts and more).

uri

-- 
Uri Guttman  ------  uri-X/06uaNR9nFmbZtjAW+qKA@xxxxxxxxxxxxxxxx  -------- 
http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org



Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>