Esteemed monks,

I am using Class::DBI and HTML::Template with CGI::Application. To speed the process of providing HTML::Template with the hashes it requires I recently added the following to my subclass:

package AppSys::DBI; use base 'Class::DBI::mysql'; sub hashy { my $self = shift; return { map { my $g = $self->get($_); $g = hashy($g) if ref $g; ( $_ => $g ); } $self->columns }; }
Code originally from PodMaster in Re: Getting HASHES out of Class::DBI. To return HASHREF's which I can pass to HTML::Template. This is fine if the method is called on a Class::DBI object. But what if I have an iterator? OK, I can 'wrap' hashy in a WHILE loop and push the returned HASHREF's onto a list and voila I can pass it to a <TMPL_LOOP..>.

My question is how do I go about determining which Class I am being called from? Am I a Class::DBI object and thus a single record being returned, or am I a Class::DBI::Iterator and thus I can iterate over myself and return a ref to a list of hashes.

jdtoronto


In reply to Help with extending Class::DBI please. by jdtoronto

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.