Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:

   +-- 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. 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 method relatively easily implementable WITHOUT using XS or anything too fancy? 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 by 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 of MyObj.

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

In reply to Class Hierarchy Design by lattice

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.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-12-09 02:20 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (37 votes). Check out past polls.