/usr/share/perl5/Pod/Sdf.pm is in sdf 2.001+1-3.
This file is owned by root:root, with mode 0o644.
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 | package Pod::Sdf;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(sdf_escape pod2sdf);
use strict;
sub sdf_escape {
my($line) = @_;
# Escape special leading characters/patterns
$line = "\\$line" if $line =~ /^\s*([-&[:>#!=*^+.\\]|[A-Z_0-9]\w*[:[])/;
# Escape phrase patterns
if ($line =~ s/\[\[/E<2[>/g) {
$line =~ s/\]\]/E<2]>/g;
}
if ($line =~ s/\{\{/E<2{>/g) {
$line =~ s/\}\}/E<2}>/g;
}
return $line;
}
sub pod2sdf {
my($pod, $param) = @_;
my(@sdf) = ();
# Get the conversion parameters
my $main = $param->{'main'};
# If the first line isn't a pod command, we need to start cutting
# until we find one
my $i;
my $line;
if (substr($$pod[0], 0, 1) ne '=') {
@sdf = ('=cut', '');
for ($i = 0; $i < scalar(@$pod); $i++) {
$line = $$pod[$i];
if ($line =~ /^\=/) {
push(@sdf, '=begin sdf', '');
last;
}
else {
push(@sdf, $line);
}
}
}
# Convert the rest
my $new_para = 1;
my $sdf_mode = 0;
my $this_type = '';
my $last_type = '';
my $in_title = '';
my $tab_size = 8;
for (; $i < scalar(@$pod); $i++) {
$line = $$pod[$i];
# Convert tabs to spaces
1 while $line =~ s/\t+/' ' x (length($&) * $tab_size - length($`) % $tab_size)/e;
# If we're in sdf mode, just pass lines through into the output
if ($sdf_mode) {
if ($line =~ /^=end\s+sdf/) {
$sdf_mode = 0;
$line =~ s/^/#/;
}
push(@sdf, $line);
next;
}
# Blank lines terminate paragraphs
if ($line =~ /^\s*$/) {
$new_para = 1;
$last_type = $this_type;
next if $in_title;
}
# To convert from POD paragraphs to SDF, the rules are:
# * tag indented lines as V (verbatim) paragraphs
# * tag normal paragraphs (with N:), if necessary
# * assume the first normal paragraph after =head NAME
# is the document name, if this is a main document
elsif ($new_para) {
if ($line =~ /^\s+/) {
$this_type = 'V';
$line = ">$line";
$sdf[$#sdf] = ">" if $last_type eq 'V';
}
elsif (substr($line, 0, 1) eq '=') {
$this_type = '=';
$in_title = $main && ($line =~ /^=head1\s+NAME\b/);
if ($in_title) {
next;
}
elsif ($line =~ /^=for\s+sdf\s*/) {
$line = $';
}
elsif ($line =~ /^=begin\s+sdf/) {
$line =~ s/^/#/;
$sdf_mode = 1;
}
else {
$line = "=" . sdf_escape(substr($line, 1));
}
}
else {
$this_type = 'N';
if ($in_title) {
$line =~ s/(['\\])/\\$1/g;
push(@sdf,
"# Build the title",
"!define DOC_NAME '$line'",
"!build_title",
'');
next;
}
else {
$line = sdf_escape($line);
}
}
$new_para = 0;
}
# For lines within a normal paragraph, we need to escape
# anything with special meaning in SDF
elsif ($this_type eq 'N') {
$line = sdf_escape($line);
}
# For lines within a verbatim paragraph, make them a
# new verbatim paragraph.
elsif ($this_type eq 'V') {
$line = ">$line";
}
# Update the output
push(@sdf, $line);
}
# If the last line is a command, we need to explicitly
# terminate it so that lines immediately following don't
# get accidently eaten by the = parsing
if ($sdf[$#sdf] =~ /^\=/) {
push(@sdf, '');
}
# Return result
return @sdf;
}
# package return value
1;
|