in reply to Re^2: CGI.pm HTML-Generation Methods Considered Useful
in thread CGI.pm HTML-Generation Methods Considered Useful

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