perlmeditation
Anno
In short, I want to invite those who are sufficiently insterested to take a
look at and comment on [href://http://www2.tu-berlin.de//zrz/mitarbeiter/anno4000/alter/Alter_pod.html|this module]. The download link is [href://http://www2.tu-berlin.de//zrz/mitarbeiter/anno4000/alter/Alter-0.02.tar.gz|here]. I intend to put the module up on CPAN.
<p>
A month ago I put up a meditation [Beyond Inside-Out] where I sketched a method to do <i>black-box inheritance</i> 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:
<p>
The basis is a function <c>Alter::ego</c>, which retrieves a class-dependent reference associated with an object. A class uses this <i>alter ego</i> for data storage. The <c>Alter::ego</c> and related functions are XS-implemented. The main disadvantage of <c>Alter</c> is that it is an external XS module, while the inside-out technique is pure perl.
<p>
The main advantages of <c>Alter</c> over inside-out objects are
<li>An unchanged data model
<p>
<blockquote>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.</blockquote>
<li>Garbage collection and thread safety
<p>
<blockquote>Perl's normal garbage-collection and thread cloning fully support <c>Alter</c>-based objects. No <c>DESTROY</c> and <c>CLONE</c> methods are required.</blockquote>
<li>Support for [mod://Data::Dumper] and [mod://Storable]
<p>
<blockquote>Viewing and serializing objects that use out-of-band data storage need support, which <c>Alter</c> provides</blockquote>