So all this work on the Perl 6 metamodel has made me really, really, really want some of the Perl 6 OO features in Perl 5. In particular things like opaque instances, inherited attributes and a sane method resolution order under multiple inheritance (C3).
Autrijus recently recomended I give Class::Std a try, since it provides many Perl6-ish features. And this morning, I did just that, and I was quite happy to find not only opaque instances (using inside-out objects), but inherited attributes as well as inherited destructors and multiply dispatching methods.
Now, being someone who actually likes to read code, I decided to go source-diving. And this being a Damian module, I was prepared for plenty of the insane code which Damian is known for. But much to my suprise, I found the code quite readable and very straightfoward.
I was happy to see that the BUILD and DESTROY orders are not the standard Perl 5 depth-first/left-to-right orderings. But instead use a custom ordering which seems to produce a fairly sane ordering. And it also seemed that the multple dispatch mechanisms and AUTOMETH feature used the same order as well.
However, I did not like the fact that these orderings stood in contrast with the way methods were actually dispatched. The standard Perl 5 method dispatch was still used for standard method dispatch. So after some head scratching and a little experimentation, I came up with Class::C3.
While still highly experimental, Class::C3 is quickly evolving, and version 0.02 should available at a CPAN mirror near you very soon. It basically pre-caches all the method dispatch to insure that the C3 method resolution ordering will be used. Version 0.02 also supports re-initializing the dispatch cache as well for those crazy people who like to mess with @ISA during runtime. I have yet to actually test it with Class::Std yet, but I suspect the two modules will get along well.
- Stevan