<?xml version="1.0" encoding="windows-1252"?>
<node id="504425" title="New Module Announcement: Object::InsideOut" created="2005-10-31 16:27:10" updated="2005-10-31 11:27:10">
<type id="23614">
perlnews</type>
<author id="313108">
jdhedden</author>
<data>
<field name="doctext">
After several weeks of intense development, I feel comfortable in releasing
(unleashing?) a new module on CPAN:
&lt;a href="http://search.cpan.org/search?module=Object%3A%3AInsideOut"&gt;Object::InsideOut&lt;/a&gt;
&lt;p&gt;
Object::InsideOut provides comprehensive support for implementing classes
using the inside-out object model.
&lt;p&gt;
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.
&lt;p&gt;
This module offers all the capabilities of Class::Std with the following
additional key advantages:
&lt;ul&gt;
&lt;li&gt;Speed -
Up to 40% 
faster than 'blessed hash' objects for fetching and setting data, and 2 to 6
times faster than Class::Std.
&lt;/li&gt;
&lt;li&gt;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 &lt;code&gt;fork&lt;/code&gt; under ActivePerl).
&lt;/li&gt;
&lt;li&gt;Flexibility -
Allows control over object ID specification, accessor naming, parameter name
matching, and more.
&lt;li&gt;mod_perl and Runtime Loading -
Usable from within mod_perl, and supports classes that may be loaded at
runtime (i.e., using eval { require ...; };).
&lt;li&gt;Exception Objects -
As recommended in 'Perl Best Practices', Object::InsideOut uses
Exception::Class for handling errors in an OO-compatible manner.
&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;&lt;/ul&gt;
&lt;b&gt;Rationale:&lt;/b&gt;&lt;br&gt;
Prior to the publication of &lt;I&gt;Perl Best Practices&lt;/I&gt;, 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 (&lt;a
href="http://search.cpan.org/search?module=Math%3A%3ARandom%3A%3AMT%3A%3AAuto"&gt;Math::Random::MT::Auto&lt;/a&gt;)
to using inside-out objects, including tackling the problem of using inside-out
objects in threaded code (i.e., &lt;code&gt;use threads;&lt;/code&gt;).
&lt;p&gt;
With the release of &lt;I&gt;Perl Best Practices&lt;/I&gt;, 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.
&lt;p&gt;
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.
&lt;p&gt;
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
&lt;code&gt;threads::shared&lt;/code&gt;.
&lt;p&gt;
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.
&lt;p&gt;
&lt;b&gt;Plea:&lt;/b&gt;&lt;br&gt;
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.
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt;&lt;br&gt;
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.
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-313108"&gt;
&lt;br&gt;&lt;font size="-1"&gt;Remember:&amp;nbsp;There's always one more bug.&lt;/font&gt;
&lt;/div&gt;&lt;/div&gt;
</field>
</data>
</node>
