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 < prev    next >
Encoding:
Text File  |  2004-03-20  |  3.6 KB  |  139 lines

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