I am on a quest for a module that I do not believe exists. So, I am planning on writing my very first CPAN module.

My requirements:

  1. Accept a query to a database, as well the database connection information, or optionally an existing DBI::db object.
  2. Accept a SQL SELECT statement and execute it
  3. Return a string containing the results wrapped in HTML table tags: <TABLE> <TR> <TH> and <TD>
  4. Allow user to specify attributes for each of the table tags, such as WIDTH, CLASS, ALIGNMENT etc.
  5. Allow user to format each <TH> and <TD> elements to allow for FONT tags. This would definately be a 'global' thing - set this value and all elements are effected
  6. Print column names headers (that is, <TH> tags)
  7. Calculate totals (and possibly subtotals) on specified columns, the columns should be accessible by their names, maybe by their number in the list of columns - user's responsibility to make sure the rows would be numeric
  8. Specify colors for the headers, totals, and body rows. Additionally allow for alternating body row colors. Two is plenty, but a configurable frequency might be nice.

Now, I have been searching CPAN, and have come across some modules that meet _some_ of my requirements:
Data::Table

Good as long as you don't mind not being able to tweak the <TD> tags without extra coding on your behalf. Plus, it has a lot of extra baggage for accessing CSV files, pulling out sub tables, sorting, etc.

Data::ShowTable I have no idea how to use this thing, I get the feeling the author doesn't want anybody to know how to use it.
DBIx::XML_RDB

This is a great start, unfortunately, it only works for XML compliant browsers. Plus you have to create style sheets

HTML::Template (or any other templating system) I use this module on a few of my projects and I love it, but for these requirements it is too much overkill. The point is to not have any other necessary files, templates, or style sheets.
The biggest missing element is none of these modules handle subtotals (with the exception of the Tempating Modules of course). The best one is
DBIx::XML_RDB, which I plan to base mine from, but with the current limiations of XML, it's not the best wide-audience choice. I have looked at a number of other modules, mostly in the DBI and HTML categories, but all them carry too much extra baggage.


So, my questions:

  1. Has anybody seen a module that meets these requirements that I did not list?
  2. Would you personally find this useful?
  3. What is a good name for it? I was planning on DBIx::HTML_Table
  4. Any suggestions for a first time CPAN writer?
Thanks,
Jeff A

In reply to SQL query to HTML table by jeffa

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.