perlnews
jdhedden
After several weeks of intense development, I feel comfortable in releasing
(unleashing?) a new module on CPAN:
<a href="http://search.cpan.org/search?module=Object%3A%3AInsideOut">Object::InsideOut</a>
<p>
Object::InsideOut provides comprehensive support for implementing classes
using the inside-out object model.
<p>
It implements inside-out objects as anonymous scalar references that
have been blessed into a class with the scalar containing the ID for the
object (usually a sequence). Object data (i.e., fields) are stored in
arrays within the class's package and are indexed on the object's ID.
<p>
This module offers all the capabilities of Class::Std with the following
additional key advantages:
<ul>
<li>Speed -
Up to 40%
faster than 'blessed hash' objects for fetching and setting data, and 2 to 6
times faster than Class::Std.
</li>
<li>Threads -
Object::InsideOut is thread safe, and
thoroughly supports sharing objects between threads using 'threads::shared'.
Class::Std is not usable in
threaded applications (or applications that use <code>fork</code> under ActivePerl).
</li>
<li>Flexibility -
Allows control over object ID specification, accessor naming, parameter name
matching, and more.
<li>mod_perl and Runtime Loading -
Usable from within mod_perl, and supports classes that may be loaded at
runtime (i.e., using eval { require ...; };).
<li>Exception Objects -
As recommended in 'Perl Best Practices', Object::InsideOut uses
Exception::Class for handling errors in an OO-compatible manner.
</li>
<li>Object Serialization - Object dumping and reloading can be accomplished in either an automated
fashion or through the use of class-supplied subroutines. Class::Std provides
a _DUMP method that is handy for debugging only, and provides no reloading capability.</li></ul>
<b>Rationale:</b><br>
Prior to the publication of <I>Perl Best Practices</I>, I came across
discussions of inside-out objects here on Perl Monks, and I liked the concept
so much that I converted my other module (<a
href="http://search.cpan.org/search?module=Math%3A%3ARandom%3A%3AMT%3A%3AAuto">Math::Random::MT::Auto</a>)
to using inside-out objects, including tackling the problem of using inside-out
objects in threaded code (i.e., <code>use threads;</code>).
<p>
With the release of <I>Perl Best Practices</I>, I looked at converting
Math::Random::MT::Auto to using Class::Std instead of my own inside-out object
support code. To my dismay, I found that Class::Std was not thread-safe. Further,
its object structure (empty scalar ref) and single method of determining object
IDs (refaddr) were incompatible with what I had written.
<p>
While I laud Damian Conway for the work he did on Class::Std, its slowness (due
to calculating the object ID at every turn), lack of thread support, and
inflexibilities (lack of support for user-supplied object ID, accessor naming
conventions, and so on) lead me to further development of my inside-out support
code. In overcoming these deficiencies, the resulting module architecture was
such that it could not be combined with Class:Std, and thus required the
issuance of an new and separate module to CPAN.
<p>
As part of the development of this module, I made sure that it incorporated all
of the functionality of Class::Std so that there would be no want for using
this module. Further, I discovered that, unlike hash-based objects, it was
possible to share scalar-based objects between threads when using
<code>threads::shared</code>.
<p>
All in all, I feel that Object::InsideOut provides comprehensive support for
the development of inside-out object classes that provides speed and
flexibility, as well as the capability to work with objects in a threaded
application complete with object sharing, if needed.
<p>
<b>Plea:</b><br>
I would like to invite my fellow monks to look at what I've developed. Hopefully,
some of you may find it useful. I would, of course, appreciate any critiques,
suggestions, ideas, etc. that you might have. Thank you.
<p>
<b>Update:</b><br>
The lastest version of Object::InsideOut supports using arrays for storing object
field data. This resulted in an impressive speed improvement (mentioned above) that I
hope will be a further incentive to my fellow monks to give Object::InsideOut a try.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-313108">
<br><font size="-1">Remember: There's always one more bug.</font>
</div></div>