I'm trying to implement a DBI-like module that handles input and output in a generic manner. I want to be able to take input from a hash, a database, freezethaw, xml, or whatever, then output it using html, xml, text, etc. The method calls would ideally take the following form:
$myObj = Obj->connect( $source, @additionalArgs ); $myObj->some_operations; $myObj->set_output( 'html' ); $myObj->output;
or something very similar (the 'connect' method could be replaced with anything, but it's familiar since DBI's pretty well known).

The way I have the object model physically structured is as follows:

Obj 
| 
+-- Input 
|    | 
|    +-- DB 
|    +-- XML
|    +-- Hash 
|    +-- etc. 
|
+-- Output 
     |
     +-- HTML 
     +-- XML 
     +-- etc. 
Now, the crux of the problem is that I don't want the programmer using this module to have to worry about creating a new Obj::Input::XML object. I want that to be part of the calling syntax, ala Tim.
I have the output portion running fine, using the $myObj->set_output( $type ) method and a symbol table / autoload approach. Would it be Kosher to use a $myObj->set_input( $type ) method to hack the symbol table so that $myObj->input points to the appropriate place, or is something like DBI's install_driver() relatively easily implementable WITHOUT using XS or anything too fancy? I can understand parts of the DBI code, but simply don't have enough time / experience to learn how the whole darn thing works internally *grin* This module is relatively lightweight (outside of its extensive use of object orientation), and I don't want to make it any bigger than necessary.

Also, I'm having some trouble deciding when to use inheritance, since it's rather a strange situation.

Should MyObj be in MyObj::Input::*'s @ISA, or should the Input::* classes inherit from a generic MyObj::Input class that doesn't inherit from MyObj? I'm rather confused, since MyObj::Input::* is used by MyObj, rather than a subclass.

I would provide an example snippet, but I'm trying to figure out the starting point, so snippets are hard to come by ;-p

Any help to smooth my very confused line of thought would be MUCH appreciated.


In reply to Object Heirarchy / Design by lattice

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.