|P is for Practical|
RFC: Alter - Perl extension for Alter Ego Objectsby Anno (Deacon)
|on Jun 30, 2007 at 15:55 UTC||Need Help??|
In short, I want to invite those who are sufficiently insterested to take a look at and comment on this module. The download link is here. I intend to put the module up on CPAN.
A month ago I put up a meditation Beyond Inside-Out where I sketched a method to do black-box inheritance in Perl without some of the drawbacks of the inside-out technique. The module above is a worked-out version of that sketch. To summarize:
The basis is a function Alter::ego, which retrieves a class-dependent reference associated with an object. A class uses this alter ego for data storage. The Alter::ego and related functions are XS-implemented. The main disadvantage of Alter is that it is an external XS module, while the inside-out technique is pure perl.
The main advantages of Alter over inside-out objects are
The alter ego of an object can be any reference. In particular, it can be a hash and the accustomed method of storing object data in hash elements can be maintained. Only now each class gets to see its individual hash.
Perl's normal garbage-collection and thread cloning fully support Alter-based objects. No DESTROY and CLONE methods are required.
Viewing and serializing objects that use out-of-band data storage need support, which Alter provides