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
In reply to Re^3: CGI.pm HTML-Generation Methods Considered Useful
by dragonchild
in thread CGI.pm HTML-Generation Methods Considered Useful
by friedo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |