An extension to the excel::template module
use Excel::Template::Plus; my $template = Excel::Template::Plus->new( engine => 'TT', template => 'greeting.tmpl', config => { INCLUDE => [ '/templates' ] }, params => { greeting => 'Hello' } ); $template->param(location => 'World'); $template->write_file('greeting.xls');
This is the very first release of this module, it is an idea that I and Rob Kinyon (the author of Excel::Template) had discussed many times, but never got around to doing. This is the first attempt at bring this to reality, it may change radically as it evolves, so be warned.
This module is an extension of the Excel::Template module, which allows the user to use various \*(L"engines\*(R" from which you can create Excel files through Excel::Template.
The idea is to use the existing (and very solid) excel file generation code in Excel::Template, but to extend its more templatey bits with more powerful options.
The only engine currently provided is the Template Toolkit engine, which replaces Excel::Template's built in template features (the \s-1LOOP\s0, and \s-1IF\s0 constructs) with the full power of \s-1TT\s0. This is similar to the module Excel::Template::TT, but expands on that even further to try and create a more extensive system.
You can use this module to create Excel::Template-compatible \s-1XML\s0 files using one of the supported engines. For example, with the \s-1TT\s0 engine you could create a Excel::Template \s-1XML\s0 file like:
<workbook> <worksheet name="[% worksheet_name %]"> [% my_cols = get_list_of_columns %] <row> [% FOR col = my_cols %] <bold><cell>[% col %]</cell></bold> [% END %] </row> [% FOR my_row = get_list_of_objects %] <row> [% FOR col = my_cols %] <cell>[% my_row.$col %]</cell> [% END %] </row> [% END %] </worksheet> </workbook>
Your \s-1TT\s0 template thus creates a \s-1XML\s0 file suitable to handing over to Excel::Template for processing. Excel::Template::Plus simplifies the template-creation and handing-over process.
Future engine/plans include:
This would allow you to write you Excel::Template files using Perl itself which would then output the \s-1XML\s0 for Excel::Template to consume. This would be modeled after the recently released Template::Declare module perhaps.
This is basically anything which will make the \s-1TT\s0 engine easier to write templates for. I have experimented with some of these things, but I was not happy with any of them enough to release them yet.
Excel::Template's templating features are based on HTML::Template, but the HTML::Template plugins and other goodies are not compatible. This engine would bring those things to Excel::Template.
This method basically serves as a factory for creating new engine instances (for which Excel::Template::Plus::TT is the only one currently). The only parameter that it requires is engine, all other parameters are passed onto the engine's constructor (see the individual docs for more details on what is required).
Access to the metaclass.
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Stevan Little <[email protected]>
Copyright 2007-2010 by Infinity Interactive, Inc.
<http://www.iinteractive.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.