Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
After several weeks of intense development, I feel comfortable in releasing (unleashing?) a new module on CPAN: Object::InsideOut

Object::InsideOut provides comprehensive support for implementing classes using the inside-out object model.

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.

This module offers all the capabilities of Class::Std with the following additional key advantages:

  • Speed - Up to 40% faster than 'blessed hash' objects for fetching and setting data, and 2 to 6 times faster than Class::Std.
  • 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 fork under ActivePerl).
  • Flexibility - Allows control over object ID specification, accessor naming, parameter name matching, and more.
  • mod_perl and Runtime Loading - Usable from within mod_perl, and supports classes that may be loaded at runtime (i.e., using eval { require ...; };).
  • Exception Objects - As recommended in 'Perl Best Practices', Object::InsideOut uses Exception::Class for handling errors in an OO-compatible manner.
  • 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.
Prior to the publication of Perl Best Practices, 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 (Math::Random::MT::Auto) to using inside-out objects, including tackling the problem of using inside-out objects in threaded code (i.e., use threads;).

With the release of Perl Best Practices, 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.

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.

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 threads::shared.

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.

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.

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.

Remember: There's always one more bug.

In reply to New Module Announcement: Object::InsideOut by jdhedden

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.