/usr/bin/pod2rst is in libpod-pom-view-restructured-perl 0.03-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | #!/usr/bin/perl
# Original authors: don
# $Revision$
use strict;
use warnings;
use Carp;
use Getopt::Long qw(:config no_ignore_case bundling);
use Pod::POM::View::Restructured;
# main
{
# local($SIG{__DIE__}) = sub { &Carp::confess };
my $self = bless { };
my $opts = $self->get_options([ "help|h",
"in_file|infile|in-file|i=s",
"out_file|outfile|out-file|o=s",
"title=s",
], { });
$self->check_options($opts, [ ]); # die's on bad options
$self->{opts} = $opts;
my ($in_fh, $out_fh) = $self->open_files;
my $conv = Pod::POM::View::Restructured->new;
my $output = $conv->convert_file($in_fh, $opts->{title}, $out_fh);
unless (defined($output)) {
print STDERR "\n\nFailed to convert!\n\n";
exit 1;
}
exit 0;
}
exit 0;
###############################################################################
# Subroutines
sub open_files {
my ($self) = @_;
my $opts = $self->{opts};
my $in_fh;
my $out_fh;
if (defined($opts->{in_file})) {
open($in_fh, '<', $opts->{in_file})
or die "couldn't open input file $opts->{in_file}: $!";
}
else {
$in_fh = \*STDIN;
}
if (defined($opts->{out_file})) {
open($out_fh, '>', $opts->{out_file})
or die "couldn't open output file $opts->{out_file}: $!";
}
else {
$out_fh = \*STDOUT;
}
return ($in_fh, $out_fh);
}
########## begin option processing ##########
sub print_usage {
print STDERR qq{\nUsage: @{[ ($0 =~ m{\A.*/([^/]+)\Z})[0] || $0 ]} options
Options:
--infile # filename for the pod to convert (input taken from
# stdin by default)
--outfile # filename for the resulting reStructuredText file
# (output sent to stdout by default)
--title # title for the document (by default an attempt will
# be made to extract the title, assuming that the first
# section is a head1 called NAME)
[-h | --help] # this help msg
\n};
}
sub check_options {
my ($self, $opts, $required) = @_;
if (not $opts or $opts->{help}) {
$self->print_usage;
exit 1;
}
my $opt_ok = 1;
$required = [ ] unless $required;
foreach my $key (@$required) {
if (defined($opts->{$key})) {
if (my $v = $opts->{$key}) {
if (my $ref = ref($v)) {
if ($ref eq 'ARRAY' ) {
unless (@$v) {
$opt_ok = 0;
warn "missing required option '$key'
";
}
}
}
}
}
else {
$opt_ok = 0;
warn "missing required option '$key'\n";
}
}
unless ($opt_ok) {
$self->print_usage;
exit 1;
}
return $opt_ok;
}
sub get_options {
my ($self, $spec, $defaults) = @_;
my %opts = $defaults ? %$defaults : ();
$spec = [ ] unless $spec;
my $process_opt = sub {
my ($key, $val) = @_;
if (scalar(@_) > 2) {
$opts{$key}{$val} = $_[2];
}
else {
if ( exists($opts{$key}) and (my $v = $opts{$key}) ) {
if (my $ref = ref($v)) {
if ($ref eq 'ARRAY' ) {
push @{ $opts{$key} }, $val;
return 1;
}
}
}
$opts{$key} = $val;
}
};
my $opt_rv = Getopt::Long::GetOptions(map { ($_ => $process_opt) } @$spec);
return $opt_rv ? \%opts : undef;
}
########## end option processing ##########
=pod
=head1 NAME
pod2rst - convert .pod files to .rst files
=head1 SYNOPSIS
=for pod2rst next-code-block: bash
pod2rst --infile=<name> --outfile=<name> --title=<name>
=head1 DESCRIPTION
Converts files containing POD to reStructuredText format for input to Sphinx.
=head1 ARGUMENTS
C<pod2rst> takes the following arguments:
=over 4
=item infile
--infile=<name>
Specifies the pod file to convert. Input is taken from stdin by default.
=item outfile
--outfile=<name>
Specifies the reStructuredText file to create. Output goes to stdout by default.
=item title
--title=<title>
Specifies the section title for the file.
=back
=head1 AUTHOR
Don Owens <don@regexguy.com>
=head1 SEE ALSO
L<Pod::POM::View::Restructured>, L<pod2html>
Sphinx: L<http://sphinx.pocoo.org/>
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2010 Don Owens <don@regexguy.com>. All rights reserved.
This is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=cut
|