1 package WebPAC::Output::TT;
6 use base qw/WebPAC::Common/;
13 WebPAC::Output::TT - use Template Toolkit to produce output
21 our $VERSION = '0.01';
25 Produce output using Template Toolkit.
33 my $tt = new WebPAC::Output::TT(
34 include_path => '/path/to/conf/output/tt',
36 filter_1 => sub { uc(shift) },
40 By default, Template Toolkit will C<EVAL_PERL> if included in templates.
49 my $log = $self->_get_logger;
51 # create Template toolkit instance
52 $self->{'tt'} = Template->new(
53 INCLUDE_PATH => $self->{'include_path'},
54 FILTERS => $self->{'filter'},
58 $log->logdie("can't create TT object: $Template::ERROR") unless ($self->{'tt'});
60 $log->debug("filters defined: ",Dumper($self->{'filter'}));
62 $self ? return $self : return undef;
68 Create output from in-memory data structure using Template Toolkit template.
70 my $text = $tt->apply(
71 template => 'text.tt',
82 my $log = $self->_get_logger();
84 foreach my $a (qw/template data/) {
85 $log->logconfess("need $a") unless ($args->{$a});
90 $self->{'tt'}->process(
94 ) || $log->logconfess( "apply can't process template: ", $self->{'tt'}->error() );
101 Create output from in-memory data structure using Template Toolkit template
106 template => 'text.tt',
117 my $log = $self->_get_logger();
119 my $file = $args->{'file'} || $log->logconfess("need file name");
121 $log->debug("creating file ",$file);
123 open(my $fh, ">", $file) || $log->logdie("can't open output file '$file': $!");
124 print $fh $self->output(
125 template => $args->{'template'},
126 data => $args->{'data'},
127 ) || $log->logdie("print: $!");
128 close($fh) || $log->logdie("close: $!");
136 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
138 =head1 COPYRIGHT & LICENSE
140 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
142 This program is free software; you can redistribute it and/or modify it
143 under the same terms as Perl itself.
147 1; # End of WebPAC::Output::TT