Subject: | AUTOMETHOD sees different address for attributes |
The AUTOMETHOD sees a different address for the attribute variables from
those seen outside of it. If the only use of the attribute variables is
from within the AUTOMETHOD, then there is no problem, since it gets a
consistent version, but if there are other uses of the attribute
variables, they fail because the attributes are based at a different
address.
As an example, I've attached a slightly modified version of the
phonebook program that was used as an example in the documentation for
Class::Std. The modifications are:
1. There is a BUILD routine to pre-initialize the phone number for
directory assistance ("Assist") into the phone book.
2. There are additional routine "get_Glenn2" and "get_Assist2" which are
hard-coded to produce the phone number for "Glenn" and "Assist",
respectively.
3. There are printouts of trying to get the phone number for directory
assistance using get_Assist, for Glen using get_Glenn2, and for
assistance using get_Assist2.
Both get_Assist (using AUTOMETHOD) and get_Glenn2 produce a null value,
while get_Assist correctly returns the result stored in the BUILD
routine. If you trace in the debugger and do a
Show quoted text
> x \%entries_of
from within AUTOMETHOD and BUILD/get_Glenn2/get_Assist, you'll see that
AUTOMETHOD thinks %entries_of is at a different address from the other
three.
Checked on perl 5.8.8 and 5.8.0.
Subject: | pb.prl |