in reply to CGI.pm HTML-Generation Methods Considered Useful

I'm curious - you mention this is for a status-monitoring application-ette. Why don't you take a little bit of time and convert it to HTML::Template or TT? You already have it in the right data format - AoH. TT can take HoH, even, and sort them.

Here's the big thing for me - CGI has nifty time-savers for generating HTML. Yet, I have NEVER been left with just generating HTML. I have always had some suit come up to me and say "Could you just export this to Excel for me?" or "Can I get a nice printout of that?" (implying PDF). Or, even worse, "Can you graph that for me?". Which is why I wrote PDF::Template, Excel::Template, and Graph::Template - to go with HTML::Template. Same data structure, but it takes me 5 minutes to convert any webpage into a PDF, XLS, or PNG. I'm not knocking CGI as a quick-hit, but I think to use its HTML generation in anything but a one-off is just begging to be hit by a rewrite-by-four.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

  • Comment on Re: CGI.pm HTML-Generation Methods Considered Useful

Replies are listed 'Best First'.
Re^2: CGI.pm HTML-Generation Methods Considered Useful
by diotalevi (Canon) on Jul 11, 2004 at 18:24 UTC
    I want to see a demo of this. Please?
      I started discussion of this concept in Re: Re: Re: Why CGI::Application. Basically, you have a single function in your CGI::Application baseclass which does all your output. The function accepts a template name, an output type, and parameters. Something like:
      my %types = ( pdf => { extension => '.pdf.xml', module => 'PDF::Template', }, xls => { extension => '.xls.xml', module => 'Excel::Template', }, html => { extension => '.tmpl', module => 'HTML::Template', }, ); sub print { my $self = shift; my ($tmpl_name, $type, @parms) = @_; my $module = $types{$type}{module}; my $template = $module->new( filename => $tmpl_name . '.' . $types{$type}{extension}; ); $template->param( @parms ); return $template->output; }

      That's the basic skeleton. Obviously, you'll want to extend that a bit, add some error-handling and defaults. But, Excel::Template and PDF::Template support the exact same API as HTML::Template, by design.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested