September 2015 Archives

Anonymous Classes With Private Data

A long while back (I’ll find the reference if I can) Stevan Little, author of Moose, commented that part of what he wanted for a p5mop was the ability to have truly private data in classes. Much in the way Perl 6 has $!data attributes that are simply private data, he wanted to just be able to use Perl’s regular variables in this same way.

I took this as a bit of a challenge and several iterations later, I had a working system. I then spent months trying to decide if I wanted to put it on CPAN. I kept weighing utility vs practicality. Though it is an interesting thought exercise, I have no idea if its a good idea.

A few things happened which made me soften my view. Most importantly, the great Damian Conway released Dios which does bring lots more of the Perl6 style classes to Perl5. This lead me to stop worrying that people would actually try to use my module for real heavy lifting; if you need that use Dios. Also Stevan gave a talk at YAPC::NA which showed an exciting and I think very promising reimagining of the p5mop project.

With these two projects out there mine can just be a curiosity. I kept finding myself showing it off and wondering. Finally, today Yanick Champoux found himself pondering blessed-subref-based objects and I reminded him of my module, which I had shown him at YAPC. I mentioned that I still was on the fence about releasing it to CPAN, he replied:

So I did.

I’m happy — and a little scared — to introduce Class:Anonymous to the CPAN. It may be the strangest thing I’ve put there yet.

About Joel Berger

user-pic As I delve into the deeper Perl magic I like to share what I can.