| Excel-Template-Plus documentation | Contained in the Excel-Template-Plus distribution. |
Excel::Template::Plus::TT - Extension of Excel::Template to use TT
use Excel::Template::Plus::TT;
# this is most commonly used through
# the Excel::Template::Plus factory
my $template = Excel::Template::Plus::TT->new(
template => 'greeting.tmpl',
config => { INCLUDE => [ '/templates' ] },
params => { greeting => 'Hello' }
);
$template->param(location => 'World');
$template->write_file('greeting.xls');
This is an engine for Excel::Template::Plus which replaces the standard Excel::Template template features with TT. See the Excel::Template::Plus docs for more information.
This provides access to getting and setting the parameters, it behaves exactly like the standard CGI.pm-style param method.
Returns the generated excel file.
Writes the generated excel file to $filename.
This will cleanup any temp files generated in the process.
Returns 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 <stevan@iinteractive.com>
Copyright 2007-2010 by Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Excel-Template-Plus documentation | Contained in the Excel-Template-Plus distribution. |
package Excel::Template::Plus::TT; use Moose; use Moose::Util::TypeConstraints; use Template (); use IO::String (); use Excel::Template; our $VERSION = '0.05'; our $AUTHORITY = 'cpan:STEVAN'; with 'MooseX::Param'; subtype 'IO::Handle' => as 'Object' => where { $_->isa('IO::Handle') }; has 'template' => ( is => 'ro', # can either be a: # - filename # - scalar ref to string # - open filehandle # - an IO::Handle instance # (basically anything TT takes) isa => 'Str | ScalarRef | FileHandle | IO::Handle', required => 1, ); has 'config' => ( is => 'ro', isa => 'HashRef', default => sub {{}}, ); has '_template_object' => ( is => "rw", isa => "Template", lazy => 1, default => sub { my $self = shift; my $class = $self->template_class; Class::MOP::load_class($class); ($class->isa('Template')) || confess "The template_class must be Template or a subclass of it"; $class->new( $self->config ) } ); has 'template_class' => ( is => "rw", isa => "Str", default => "Template", ); ## private attributes has '_excel_template' => ( is => 'ro', isa => 'Excel::Template', handles => [qw[ output write_file ]], lazy => 1, default => sub { my $self = shift; $self->_prepare_excel_template; } ); sub _prepare_excel_template { my $self = shift; my $buf; my $fh = IO::String->new(\$buf); my $tt = $self->_template_object; $tt->process( $self->template, $self->params, $fh, ); $fh->pos(0); confess "Template creation failed because : " . $tt->error() if $tt->error(); confess "Template failed to produce any output" unless length($buf); my $excel_template = eval { Excel::Template->new(file => $fh) }; if ($@) { warn $buf; confess $@; } return $excel_template; } no Moose; no Moose::Util::TypeConstraints; 1; __END__