From: Russ Allbery [mailto:[EMAIL PROTECTED]]
> David M Lloyd <[EMAIL PROTECTED]> writes:
> > On 24 Apr 2001, Russ Allbery wrote:
> > >
> > > It seems relatively unlikely in the course of normal Perl
> > > that you're going to end up with very many references to
> > > objects.
> >
> > Well, right now in Perl, an object *is* a reference.
>
> Precisely. So there's almost never any reason to create a
> reference to an object, which would be a reference to a
> reference, and for those rare circumstances the existing
> dereference syntax is probably adequate.
How many classes uses a flyweight scalar reference to work around circular
references in garbage collection? Class::Contract does. Also, if it is
common enough to be covered in the Perl Cookbook (13.13)... it probably
isn't too uncommon.
Class::Contract provides a generic constructor which returns a reference to
a reference.
my $key = \ my $undef;
my $obj = \ $key;
bless $obj, $class;
This is to avoid circular references while providing better encapsulation.
$obj is a flyweight reference to $key. Object attribute accessors lookup
object data in the Class::Contract lexical %data. There is no way to get at
an object's data except through the interface defined in the "contract".
When the $obj goes out of scope, the Class::Contract provided destructor
deletes $data{$key}.
Now all that that means, is that it isn't uncommon that an object might be a
reference to a reference. It is up to the user to decide to make a reference
to that object. But I'd venture to guess that that isn't an all too uncommon
thing.
> I would presume that objects will still be implemented as
> references under the hood so that passing them around is
> efficient no matter what they contain.
I guess that falls back into Branden's thread of tying variables vs.
overloading values. Which to me is overloading accessors vs. methods. When
someone overloads @foo to be an instance of Foo, is that tying per Perl 5:
magic variables which redirect variable accessors to a class... or something
new? I certainly hope magic in perl 6 is reincarnated as something much more
accessible at runtime to users.