home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / tpage.bat < prev    next >
Encoding:
DOS Batch File  |  2004-03-20  |  4.0 KB  |  155 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!/usr/bin/perl -w
  14. #line 15
  15. #========================================================================
  16. #
  17. # tpage
  18. #
  19. # DESCRIPTION
  20. #   Script for processing and rendering a template document using the 
  21. #   Perl Template Toolkit. 
  22. #
  23. # AUTHOR
  24. #   Andy Wardley   <abw@kfs.org>
  25. #
  26. # COPYRIGHT
  27. #   Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
  28. #   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
  29. #
  30. #   This module is free software; you can redistribute it and/or
  31. #   modify it under the same terms as Perl itself.
  32. #
  33. #------------------------------------------------------------------------
  34. #
  35. # $Id: tpage.bat,v 1.3 2004/03/20 23:00:29 joker Exp $
  36. #
  37. #========================================================================
  38.  
  39. use strict;
  40. use Template;
  41.  
  42. # look for -h or --help option, print usage and exit
  43. if (grep /^--?h(elp)?/, @ARGV) {
  44.     print "usage: tpage file [ file [...] ]\n";
  45.     exit 0;
  46. }
  47. my $vars = { };
  48. my ($var, $val);
  49.  
  50. while ($ARGV[0] && $ARGV[0] =~ /^--?d(efine)?/) {
  51.     shift(@ARGV);
  52.     die "--define expect a 'variable=value' argument\n" 
  53.     unless defined ($var = shift(@ARGV));
  54.     ($var, $val) = split(/\s*=\s*/, $var, 2);
  55.     $vars->{ $var } = $val;
  56. }
  57.  
  58. # read from STDIN if no files specified
  59. push(@ARGV, '-') unless @ARGV;
  60.  
  61. # create a template processor 
  62. my $template = Template->new({
  63.     ABSOLUTE => 1,
  64.     RELATIVE => 1,
  65. });
  66.  
  67. # process each input file 
  68. foreach my $file (@ARGV) {
  69.     $file = \*STDIN if $file eq '-';
  70.     $template->process($file, $vars)
  71.     || die $template->error();
  72. }
  73.  
  74. __END__
  75.  
  76.  
  77. #------------------------------------------------------------------------
  78. # IMPORTANT NOTE
  79. #   This documentation is generated automatically from source
  80. #   templates.  Any changes you make here may be lost.
  81. #   The 'docsrc' documentation source bundle is available for download
  82. #   from http://www.template-toolkit.org/docs.html and contains all
  83. #   the source templates, XML files, scripts, etc., from which the
  84. #   documentation for the Template Toolkit is built.
  85. #------------------------------------------------------------------------
  86.  
  87. =head1 NAME
  88.  
  89. Template::Tools::tpage - Process templates from command line
  90.  
  91. =head1 USAGE
  92.  
  93.     tpage [ --define var=value ] file(s)
  94.  
  95. =head1 DESCRIPTION
  96.  
  97. The B<tpage> script is a simple wrapper around the Template Toolkit processor.
  98. Files specified by name on the command line are processed in turn by the 
  99. template processor and the resulting output is sent to STDOUT and can be 
  100. redirected accordingly.  e.g.
  101.  
  102.     tpage myfile > myfile.out
  103.     tpage header myfile footer > myfile.html
  104.  
  105. If no file names are specified on the command line then B<tpage> will read
  106. STDIN for input.
  107.  
  108. The C<--define> option can be used to set the values of template variables.
  109. e.g.
  110.  
  111.     tpage --define author="Andy Wardley" skeleton.pm > MyModule.pm
  112.  
  113. See L<Template> for general information about the Perl Template 
  114. Toolkit and the template language and features.
  115.  
  116. =head1 AUTHOR
  117.  
  118. Andy Wardley E<lt>abw@andywardley.comE<gt>
  119.  
  120. L<http://www.andywardley.com/|http://www.andywardley.com/>
  121.  
  122.  
  123.  
  124.  
  125. =head1 VERSION
  126.  
  127. 2.69, distributed as part of the
  128. Template Toolkit version 2.13, released on 30 January 2004.
  129.  
  130. =head1 COPYRIGHT
  131.  
  132.   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  133.   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  134.  
  135. This module is free software; you can redistribute it and/or
  136. modify it under the same terms as Perl itself.
  137.  
  138. =head1 SEE ALSO
  139.  
  140. L<ttree|Template::Tools::ttree>
  141.  
  142. =cut
  143.  
  144. # Local Variables:
  145. # mode: perl
  146. # perl-indent-level: 4
  147. # indent-tabs-mode: nil
  148. # End:
  149. #
  150. # vim: expandtab shiftwidth=4:
  151.  
  152. __END__
  153. :endofperl
  154.