stevan/p5-mop — Issue #31: Interaction with anonymous packages
Author: cpansprout
Created: 2011-12-12 07:59:20+00:00
State: open

I think this may be off-topic, but I thought I should bring it up:

For a long time now, I’ve been thinking about how anonymous packages in Perl might work.

(It was Florian Ragwitz who brought up the idea just over a year ago, when he asked me about the feasibility of MRO plugins’ providing lists of HVs instead of package names.)

More recently, I’ve thought about simple package { ... } syntax (i.e., without the name, like sub { ... }).

The main issue (and Zefram brought this up on p5p) is: What should an anonymous package look like on the outside?

So, in the end, we have to introduce a new concept. I started wondering whether it is worthwhile to introduce two new concepts at the same time: We now have this brand new object system. Oh, and look, we also extended the old one!

That might cause more confusion than it is worth. People will be asking: Well, which one do I use?

But being able to take references to packages and move them around is immensely useful.

I suppose I bring this up to see whether anyone has comments on how it might interact with the new object system, especially if multiple anonymous packages and classes could nest.

For package{...} I was thinking it should clone the package and then run its main CV, which would be like a closure that runs immediately. The return value would be a STASH ref. A STASH would simply be a hash flagged in such a way that ref() returns STASH instead. Method calls on unblessed STASH refs would be permitted.