Add built local::lib
[catagits/Gitalist.git] / local-lib5 / bin / tpage
1 #!/usr/bin/perl -w
2
3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4     if 0; # not running under some shell
5 #========================================================================
6 #
7 # tpage
8 #
9 # DESCRIPTION
10 #   Script for processing and rendering a template document using the 
11 #   Perl Template Toolkit. 
12 #
13 # AUTHOR
14 #   Andy Wardley   <abw@kfs.org>
15 #
16 # COPYRIGHT
17 #   Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
18 #   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
19 #
20 #   This module is free software; you can redistribute it and/or
21 #   modify it under the same terms as Perl itself.
22 #
23 #------------------------------------------------------------------------
24 #
25 # $Id: tpage 1068 2007-04-27 13:33:25Z abw $
26 #
27 #========================================================================
28
29 use strict;
30 use Template;
31 use AppConfig;
32
33 my $NAME     = "tpage";
34 my $VERSION  = 2.70;
35 my $HOME     = $ENV{ HOME } || '';
36 my $RCFILE   = $ENV{"\U${NAME}rc"} || "$HOME/.${NAME}rc";
37 my $TTMODULE = 'Template';
38
39 # read .tpagerc file and any command line arguments
40 my $config   = read_config($RCFILE);
41
42 # unshift any perl5lib directories onto front of INC
43 unshift(@INC, @{ $config->perl5lib });
44
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 });
48 my $ucttopts = {
49     map { my $v = $ttopts{ $_ }; defined $v ? (uc $_, $v) : () }
50     keys %ttopts,
51 };
52
53 # load custom template module 
54 if ($ttmodule) {
55     my $ttpkg = $ttmodule;
56     $ttpkg =~ s[::][/]g;
57     $ttpkg .= '.pm';
58     require $ttpkg;
59 }
60 else {
61     $ttmodule = $TTMODULE;
62 }
63
64 # add current directory to INCLUDE_PATH
65 unshift(@{ $ucttopts->{ INCLUDE_PATH } }, '.');
66
67 # read from STDIN if no files specified
68 push(@ARGV, '-') unless @ARGV;
69
70 my $template = $ttmodule->new($ucttopts)
71     || die $ttmodule->error();
72
73 # process each input file 
74 foreach my $file (@ARGV) {
75     $file = \*STDIN if $file eq '-';
76     $template->process($file)
77         || die $template->error();
78 }
79
80
81 sub read_config {
82     my $file = shift;
83
84     my $config = AppConfig->new(
85         { 
86             ERROR  => sub { die(@_, "\ntry `$NAME --help'\n") }
87         }, 
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',
98         'template_trim|trim',
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@'
117     );
118
119     # add the 'file' option now that we have a $config object that we 
120     # can reference in a closure
121     $config->define(
122         'file|f=s@' => { 
123             EXPAND => AppConfig::EXPAND_ALL, 
124             ACTION => sub { 
125                 my ($state, $item, $file) = @_;
126                 $file = $state->cfg . "/$file" 
127                     unless $file =~ /^[\.\/]|(?:\w:)/;
128                 $config->file($file) }  
129         }
130     );
131
132     # process main config file, then command line args
133     $config->file($file) if -f $file;
134     $config->args();
135     return $config;
136 }
137
138
139 sub help {
140     print<<END_OF_HELP;
141 $NAME $VERSION (Template Toolkit version $Template::VERSION)
142
143 usage: $NAME [options] [files]
144
145 Options:
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
172
173 See 'perldoc tpage' for further information.  
174
175 END_OF_HELP
176
177     exit(0);
178 }
179
180 __END__
181
182
183 #------------------------------------------------------------------------
184 # IMPORTANT NOTE
185 #   This documentation is generated automatically from source
186 #   templates.  Any changes you make here may be lost.
187
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 #------------------------------------------------------------------------
193
194 =head1 NAME
195
196 Template::Tools::tpage - Process templates from command line
197
198 =head1 USAGE
199
200     tpage [ --define var=value ] file(s)
201
202 =head1 DESCRIPTION
203
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.
208
209     tpage myfile > myfile.out
210     tpage header myfile footer > myfile.html
211
212 If no file names are specified on the command line then B<tpage> will read
213 STDIN for input.
214
215 The C<--define> option can be used to set the values of template variables.
216 e.g.
217
218     tpage --define author="Andy Wardley" skeleton.pm > MyModule.pm
219
220 See L<Template> for general information about the Perl Template 
221 Toolkit and the template language and features.
222
223 =head1 AUTHOR
224
225 Andy Wardley E<lt>abw@wardley.orgE<gt>
226
227 L<http://wardley.org/|http://wardley.org/>
228
229
230
231
232 =head1 VERSION
233
234 2.68, distributed as part of the
235 Template Toolkit version 2.19, released on 27 April 2007.
236
237 =head1 COPYRIGHT
238
239   Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
240
241
242 This module is free software; you can redistribute it and/or
243 modify it under the same terms as Perl itself.
244
245 =head1 SEE ALSO
246
247 L<ttree|Template::Tools::ttree>
248
249 =cut
250
251 # Local Variables:
252 # mode: perl
253 # perl-indent-level: 4
254 # indent-tabs-mode: nil
255 # End:
256 #
257 # vim: expandtab shiftwidth=4: