Front page | perl.perl5.porters |
Postings from September 2011
Re: Package:: still ambiguous
Thread Previous
|
Thread Next
From:
Zefram
Date:
September 14, 2011 08:11
Subject:
Re: Package:: still ambiguous
Message ID:
20110914151054.GA16583@lake.fysh.org
Nicholas Clark wrote:
>On Wed, Sep 14, 2011 at 01:55:15PM +0100, Zefram wrote:
>> probably end up implemented as an svtype, SVt_PVPK.
>
>On boy, is that going to break any XS code that processes hashes,
>identifies hashes as SvTYPE(sv) == SVt_PVHV, and is used by any other
>code that passes in stashes, knowing that stashes are just hashes.
I imagine the namespace part of a package continuing to be implemented
as a hash. %Package:: can continue to refer to that hash, which can
continue to be an SVt_PVHV, without that having to be the same as the
package object. (I have a nagging concern about extra memory usage if we
separate stash from package object, but I doubt it would be substantial.)
Of course, any version of this will break much code that does more
interesting things with stashes. I think it's OK to break most stash
stuff, but anything we're presenting as a hash should be as normal a
hash as it can be.
Here's another concept for package objects that I came up with this
morning: the package can be represented by an object that's blessed
into itself. So ref($pkg) gives you the package name, preserving the
"ref($_[0]) || $_[0]" idiom, and providing a natural way to dispatch
class methods. Blessing the package object into some other package (one
of my sources of trouble) would rather obviously constitute breaking the
package, meriting a "don't do that then" response. Downside is increased
likelihood of mistaking the package object for an instance of the class,
especially if the package object is actually the HV stash.
Also, a concept for how ref($obj) should behave on anonymous classes:
make the class not actually anonymous, just weakly referenced by its name.
new_anon_package() gensyms a name, sets up a package by that name, and
returns a ref to the package object. However, the reference to the stash
or package object from the name is weak, so the package only continues to
exist as long as there's a hard ref to the package object or an instance.
So it doesn't survive unduly long if it was a temporary class, yet it
still has a fully working name as long as it does survive.
These are just concepts, of course, not complete designs. Anyone else
want to join in at this blue sky stage?
-zefram
Thread Previous
|
Thread Next