3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
5 #========================================================================
10 # Script for processing and rendering a template document using the
11 # Perl Template Toolkit.
14 # Andy Wardley <abw@kfs.org>
17 # Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
18 # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
20 # This module is free software; you can redistribute it and/or
21 # modify it under the same terms as Perl itself.
23 #------------------------------------------------------------------------
25 # $Id: tpage 1068 2007-04-27 13:33:25Z abw $
27 #========================================================================
35 my $HOME = $ENV{ HOME } || '';
36 my $RCFILE = $ENV{"\U${NAME}rc"} || "$HOME/.${NAME}rc";
37 my $TTMODULE = 'Template';
39 # read .tpagerc file and any command line arguments
40 my $config = read_config($RCFILE);
42 # unshift any perl5lib directories onto front of INC
43 unshift(@INC, @{ $config->perl5lib });
45 # get all template_* options from the config and fold keys to UPPER CASE
46 my %ttopts = $config->varlist('^template_', 1);
47 my $ttmodule = delete($ttopts{ module });
49 map { my $v = $ttopts{ $_ }; defined $v ? (uc $_, $v) : () }
53 # load custom template module
55 my $ttpkg = $ttmodule;
61 $ttmodule = $TTMODULE;
64 # add current directory to INCLUDE_PATH
65 unshift(@{ $ucttopts->{ INCLUDE_PATH } }, '.');
67 # read from STDIN if no files specified
68 push(@ARGV, '-') unless @ARGV;
70 my $template = $ttmodule->new($ucttopts)
71 || die $ttmodule->error();
73 # process each input file
74 foreach my $file (@ARGV) {
75 $file = \*STDIN if $file eq '-';
76 $template->process($file)
77 || die $template->error();
84 my $config = AppConfig->new(
86 ERROR => sub { die(@_, "\ntry `$NAME --help'\n") }
88 'help|h' => { ACTION => \&help },
89 'template_absolute|absolute' => { DEFAULT => 1 },
90 'template_relative|relative' => { DEFAULT => 1 },
91 'template_module|module=s',
92 'template_anycase|anycase',
93 'template_eval_perl|eval_perl',
94 'template_load_perl|load_perl',
95 'template_interpolate|interpolate',
96 'template_pre_chomp|pre_chomp|prechomp',
97 'template_post_chomp|post_chomp|postchomp',
99 'template_variables|variables|define=s%',
100 'template_include_path|include_path|include|I=s@',
101 'template_pre_process|pre_process|preprocess=s@',
102 'template_post_process|post_process|postprocess=s@',
103 'template_process|process=s',
104 'template_wrapper|wrapper=s',
105 'template_recursion|recursion',
106 'template_expose_blocks|expose_blocks',
107 'template_default|default=s',
108 'template_error|error=s',
109 'template_debug|debug=s',
110 'template_start_tag|start_tag|starttag=s',
111 'template_end_tag|end_tag|endtag=s',
112 'template_tag_style|tag_style|tagstyle=s',
113 'template_compile_ext|compile_ext=s',
114 'template_compile_dir|compile_dir=s',
115 'template_plugin_base|plugin_base|pluginbase=s@',
116 'perl5lib|perllib=s@'
119 # add the 'file' option now that we have a $config object that we
120 # can reference in a closure
123 EXPAND => AppConfig::EXPAND_ALL,
125 my ($state, $item, $file) = @_;
126 $file = $state->cfg . "/$file"
127 unless $file =~ /^[\.\/]|(?:\w:)/;
128 $config->file($file) }
132 # process main config file, then command line args
133 $config->file($file) if -f $file;
141 $NAME $VERSION (Template Toolkit version $Template::VERSION)
143 usage: $NAME [options] [files]
146 --define var=value Define template variable
147 --interpolate Interpolate '\$var' references in text
148 --anycase Accept directive keywords in any case.
149 --pre_chomp Chomp leading whitespace
150 --post_chomp Chomp trailing whitespace
151 --trim Trim blank lines around template blocks
152 --eval_perl Evaluate [% PERL %] ... [% END %] code blocks
153 --load_perl Load regular Perl modules via USE directive
154 --absolute Allow ABSOLUTE directories (enabled by default)
155 --relative Allow RELATIVE directories (enabled by default)
156 --include_path=DIR Add directory to INCLUDE_PATH
157 --pre_process=TEMPLATE Process TEMPLATE before each main template
158 --post_process=TEMPLATE Process TEMPLATE after each main template
159 --process=TEMPLATE Process TEMPLATE instead of main template
160 --wrapper=TEMPLATE Process TEMPLATE wrapper around main template
161 --default=TEMPLATE Use TEMPLATE as default
162 --error=TEMPLATE Use TEMPLATE to handle errors
163 --debug=STRING Set TT DEBUG option to STRING
164 --start_tag=STRING STRING defines start of directive tag
165 --end_tag=STRING STRING defined end of directive tag
166 --tag_style=STYLE Use pre-defined tag STYLE
167 --plugin_base=PACKAGE Base PACKAGE for plugins
168 --compile_ext=STRING File extension for compiled template files
169 --compile_dir=DIR Directory for compiled template files
170 --perl5lib=DIR Specify additional Perl library directories
171 --template_module=MODULE Specify alternate Template module
173 See 'perldoc tpage' for further information.
183 #------------------------------------------------------------------------
185 # This documentation is generated automatically from source
186 # templates. Any changes you make here may be lost.
188 # The 'docsrc' documentation source bundle is available for download
189 # from http://www.template-toolkit.org/docs.html and contains all
190 # the source templates, XML files, scripts, etc., from which the
191 # documentation for the Template Toolkit is built.
192 #------------------------------------------------------------------------
196 Template::Tools::tpage - Process templates from command line
200 tpage [ --define var=value ] file(s)
204 The B<tpage> script is a simple wrapper around the Template Toolkit processor.
205 Files specified by name on the command line are processed in turn by the
206 template processor and the resulting output is sent to STDOUT and can be
207 redirected accordingly. e.g.
209 tpage myfile > myfile.out
210 tpage header myfile footer > myfile.html
212 If no file names are specified on the command line then B<tpage> will read
215 The C<--define> option can be used to set the values of template variables.
218 tpage --define author="Andy Wardley" skeleton.pm > MyModule.pm
220 See L<Template> for general information about the Perl Template
221 Toolkit and the template language and features.
225 Andy Wardley E<lt>abw@wardley.orgE<gt>
227 L<http://wardley.org/|http://wardley.org/>
234 2.68, distributed as part of the
235 Template Toolkit version 2.19, released on 27 April 2007.
239 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
242 This module is free software; you can redistribute it and/or
243 modify it under the same terms as Perl itself.
247 L<ttree|Template::Tools::ttree>
253 # perl-indent-level: 4
254 # indent-tabs-mode: nil
257 # vim: expandtab shiftwidth=4: