File: pom2

package info (click to toggle)
libpod-pom-perl 0.17-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 232 kB
  • ctags: 142
  • sloc: perl: 1,880; makefile: 50
file content (107 lines) | stat: -rwxr-xr-x 2,209 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl -w
#
# This program implements a simple translator to convert POD
# to HTML, Text, or back to POD again (e.g. for normalising a 
# document).  You can easily extend it to work with any other
# view modules you create which convert POD to different formats
# or in different styles.
#
# Written by Andy Wardley <abw@kfs.org>.   This is free software.
#

use Pod::POM;
use File::Basename;

my $PROGRAM = 'pom2';
my $program = basename($0);
my $format;
my $views = {
    pod  => 'Pod',
    text => 'Text',
    html => 'HTML',
};

die usage() if grep(/^--?h(elp)?$/, @ARGV);

if ($program =~ /^$PROGRAM(.+)$/) {
    $format = $1;
}
else {
    $format = shift 
	|| die usage('no output format specified');
}

my $file = shift 
    || die usage('no filename specified');

$format = lc $format;
my $view = $views->{ $format } 
    || die usage("invalid format '$format', try one of: " 
	        . join(', ', keys %$views));

$view = "Pod::POM::View::$view";
Pod::POM->default_view($view)
    || die "$Pod::POM::ERROR\n";

my $parser = Pod::POM->new( warn => 1 )
    || die "$Pod::POM::ERROR\n";

my $pom = $parser->parse_file($file)
    || die $parser->error(), "\n";

print $pom;


#------------------------------------------------------------------------

sub usage {
    my $msg = shift || '';

    if ($program =~ /^$PROGRAM$/) {
	$program = "pom2 format";
    }
    
    return <<EOF;
${msg}
usage: $program file
EOF
}

__END__

=head1 NAME

pom2 - convert POD to Text, HTML, etc., with Pod::POM

=head1 SYNOPSIS

    pom2 text MyFile.pm > MyFile.txt
    pom2 html MyFile.pm > MyFile.html
    pom2 pod  MyFile.pm > Myfile.pod

=head1 DESCRIPTION

This script uses Pod::POM to convert a Pod document into text,
HTML, back into Pod (e.g. to normalise a document to fix any 
markup errors), or any other format for which you have a view
module.

=head1 AUTHOR

Andy Wardley E<lt>abw@kfs.orgE<gt>

=head1 VERSION

This is version 0.2 of pom2.

=head1 COPYRIGHT

Copyright (C) 2000, 2001 Andy Wardley.  All Rights Reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 SEE ALSO

For further information please see L<Pod::POM>.