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 / pom2 < prev    next >
Encoding:
Text File  |  2001-12-06  |  2.2 KB  |  108 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # This program implements a simple translator to convert POD
  4. # to HTML, Text, or back to POD again (e.g. for normalising a 
  5. # document).  You can easily extend it to work with any other
  6. # view modules you create which convert POD to different formats
  7. # or in different styles.
  8. #
  9. # Written by Andy Wardley <abw@kfs.org>.   This is free software.
  10. #
  11.  
  12. use Pod::POM;
  13. use File::Basename;
  14.  
  15. my $PROGRAM = 'pom2';
  16. my $program = basename($0);
  17. my $format;
  18. my $views = {
  19.     pod  => 'Pod',
  20.     text => 'Text',
  21.     html => 'HTML',
  22. };
  23.  
  24. die usage() if grep(/^--?h(elp)?$/, @ARGV);
  25.  
  26. if ($program =~ /^$PROGRAM(.+)$/) {
  27.     $format = $1;
  28. }
  29. else {
  30.     $format = shift 
  31.     || die usage('no output format specified');
  32. }
  33.  
  34. my $file = shift 
  35.     || die usage('no filename specified');
  36.  
  37. $format = lc $format;
  38. my $view = $views->{ $format } 
  39.     || die usage("invalid format '$format', try one of: " 
  40.             . join(', ', keys %$views));
  41.  
  42. $view = "Pod::POM::View::$view";
  43. Pod::POM->default_view($view)
  44.     || die "$Pod::POM::ERROR\n";
  45.  
  46. my $parser = Pod::POM->new( warn => 1 )
  47.     || die "$Pod::POM::ERROR\n";
  48.  
  49. my $pom = $parser->parse_file($file)
  50.     || die $parser->error(), "\n";
  51.  
  52. print $pom;
  53.  
  54.  
  55. #------------------------------------------------------------------------
  56.  
  57. sub usage {
  58.     my $msg = shift || '';
  59.  
  60.     if ($program =~ /^$PROGRAM$/) {
  61.     $program = "pom2 format";
  62.     }
  63.     
  64.     return <<EOF;
  65. ${msg}
  66. usage: $program file
  67. EOF
  68. }
  69.  
  70. __END__
  71.  
  72. =head1 NAME
  73.  
  74. pom2 - convert POD to Text, HTML, etc., with Pod::POM
  75.  
  76. =head1 SYNOPSIS
  77.  
  78.     pom2 text MyFile.pm > MyFile.txt
  79.     pom2 html MyFile.pm > MyFile.html
  80.     pom2 pod  MyFile.pm > Myfile.pod
  81.  
  82. =head1 DESCRIPTION
  83.  
  84. This script uses Pod::POM to convert a Pod document into text,
  85. HTML, back into Pod (e.g. to normalise a document to fix any 
  86. markup errors), or any other format for which you have a view
  87. module.
  88.  
  89. =head1 AUTHOR
  90.  
  91. Andy Wardley E<lt>abw@kfs.orgE<gt>
  92.  
  93. =head1 VERSION
  94.  
  95. This is version 0.2 of pom2.
  96.  
  97. =head1 COPYRIGHT
  98.  
  99. Copyright (C) 2000, 2001 Andy Wardley.  All Rights Reserved.
  100.  
  101. This module is free software; you can redistribute it and/or
  102. modify it under the same terms as Perl itself.
  103.  
  104. =head1 SEE ALSO
  105.  
  106. For further information please see L<Pod::POM>.
  107.  
  108.