I've gotten some good feedback here and through email on my DBIx::Pretty module; the basics are fine, but I want to expand it to be extendable (see Scope of a Module?), and to handle a few more data types. I want to pass some ideas through PM as the changes are significant enough that I only want to program the bulk of this once.

First and foremost, I'm not trying to abstract away SQL; DBIx::Pretty is meant to be a cleaner SQL-in-code as opposed to replacing it. That is, DBIx::Pretty is to SQL as HTML::Template (and friends) is to HTML.

Secondly, DBIx::Pretty was renamed from DBI::Pretty due to the naming convention in the DBI:: module tree; that is, only DBI and it's directly database glue should go here, any DBI extentions should go to DBIx::.

The main goal of DBIx::Pretty is to assign names to SQL statements, then be able to call those SQL statements directly through their name in an AUTOLOAD manner; in addition, there's some variable substituion that can go on in the SQL statement for placeholders as well as other variable parts of the SQL statement. You can see more details in my original code.

Now, there are two areas that I'm trying to improve on:

First is the actually extensibility. The way I will set this up is to have DBIx::Pretty, then several subclasses, the default being DBIx::Pretty::Hash. In D:P, the three key functions than any subclass should override in my current scheme are:

The idea is that there can be static or dynamic SQL bindings. In static cases, the SQL is loaded and preparsed, with the preparse data going into an internal cache. In dynamic cases where the SQL might change, the subclass can have, for that sql, return in get_sql_properties some flag that indicates that the sql statement should be processed, but the preprocessing data is not cache and dumped away.

The suclasses are free to define additional methods; for example, I know that D:P:Hash will also have add_sql and remove_sql calls that add to it.

The second aspect is the variable interpolation. As I have it now, there's two types of variables:

I'm thinking of adding two more types: As an example of all this working together, I could define a meta-SQL set of statements as:
query => SELECT $fields FROM $table WHERE #conditions age_check => age > ?age gender_check => gender LIKE ?gender ... # actual call... $dbixprettyobj -> query ( { conditions=>"&age_check AND &gender_check", age=>18, gender=>'M', fields=> "name, id", table=>users } );

In addition, I'm considering allowing variables to have at least one addition field, that is associated with the variable in question by appending ":value" to it. The value that follows would be the default value for that variable if it is not defined in the hash that is passed to the AUTOLOAD function. So, in the above, if I has "?age:18", then if I didn't pass an age field in the hash, the code would automatically plug in 18 there.

From the coding standpoint, I know there's a lot here with regards to checking and the like (for example, avoiding infinite recursion loops in the inclusion/sql-statement variable types), but I'm more interested from here on commentary on how the user's interface is laid out. Do the variable types make sense and am I missing anything obvious that might interfere with typical SQL statements?

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain


In reply to Open for suggestions on DBIx::Pretty by Masem

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.