ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/pod.pm
(Generate patch)

Comparing deliantra/server/lib/cf/pod.pm (file contents):
Revision 1.8 by root, Tue Jul 3 01:10:38 2007 UTC vs.
Revision 1.20 by root, Wed Oct 21 00:44:39 2009 UTC

1package cf::pod; 1package cf::pod;
2
3use common::sense;
2 4
3use Pod::POM; 5use Pod::POM;
4 6
5our $indent; 7our $indent;
6our $level; 8our $level;
7our @result; 9our @result;
8 10
9package cf::pod::AsParagraphs; 11package cf::pod::AsParagraphs;
10 12
11use strict; 13use common::sense;
12 14
13use base "Pod::POM::View"; 15use base "Pod::POM::View";
14 16
17my %E = (
18 "<" => "E<lt>",
19 ">" => "E<gt>",
20);
21
15sub asxml($) { 22sub aspod($) {
16 local $_ = $_[0]; 23 local $_ = $_[0];
17 24
18 s/&/&amp;/g; 25 s/[<>]/$E{$1}/g;
19 s/>/&gt;/g;
20 s/</&lt;/g;
21 26
22 $_ 27 $_
23} 28}
24 29
25sub flatten($) { 30sub flatten($) {
26 local $_ = $_[0]; 31 local $_ = $_[0];
27 32
28 s/<[^>]+>//g;
29 s/^\s+//; 33 s/^\s+//;
30 s/\s+$//; 34 s/\s+$//;
31 s/\s+/ /g; 35 s/\s+/ /g;
32 36
33 $_ 37 $_
34} 38}
35 39
36*view_seq_file = 40*view_seq_file = sub { "C<$_[1]>" };
37*view_seq_code = 41*view_seq_code = sub { "C<$_[1]>" };
38*view_seq_bold = sub { "<b>$_[1]</b>" }; 42*view_seq_bold = sub { "B<$_[1]>" };
39*view_seq_italic = sub { "<i>$_[1]</i>" }; 43*view_seq_italic = sub { "I<$_[1]>" };
44*view_seq_T = sub { "T<$_[1]>" };
45*view_seq_G = sub { "G<$_[1]>" };
40*view_seq_zero = sub { }; 46*view_seq_zero = sub { "Z<>" };
41*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; 47*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
42*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 48*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
43 49
44sub view_seq_text { 50sub view_seq_text {
45 my $text = $_[1]; 51 my $text = $_[1];
46 $text =~ s/\s+/ /g; 52 $text =~ s/\s+/ /g;
47 asxml $text 53 aspod $text
48} 54}
49 55
50sub view_seq_link { 56sub view_seq_link {
51 my (undef, $link) = @_; 57 my (undef, $link) = @_;
52 58
53 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 59 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
54 60
55 if ($link =~ /http:/) { 61 if ($link =~ /http:/) {
56 "<u>" . (asxml $link) . "</u>" 62 "U<" . (aspod $link) . ">"
57 } else { 63 } else {
58 () 64 ()
59 } 65 }
60} 66}
61 67
76sub view_verbatim { 82sub view_verbatim {
77 push @result, { 83 push @result, {
78 type => "verbatim", 84 type => "verbatim",
79 indent => $indent * 16, 85 indent => $indent * 16,
80 level => $level, 86 level => $level,
81 markup => asxml $_[1], 87 markup => $_[1],
82 }; 88 };
83 () 89 ()
84} 90}
85 91
86sub view_textblock { 92sub view_textblock {
183 189
184sub load_pod($) { 190sub load_pod($) {
185 my ($path) = @_; 191 my ($path) = @_;
186 192
187 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], 193 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
188 1 => sub { 194 7 => sub {
189 my ($src) = @_; 195 my ($src) = @_;
196
190 cf::fork_call { 197 cf::fork_call {
191 my $pod = $src->[0]; 198 my $pod = $src->[0];
192 utf8::decode $pod; 199 utf8::decode $pod;
193 Coro::Storable::freeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) 200 Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod))
194 } 201 }
195 }; 202 };
196} 203}
197 204
198# format as cfpod-style text 205# format as cfpod-style text
199sub as_text($) { 206sub as_cfpod($) {
200 my ($pars) = @_; 207 my ($pars) = @_;
201 208
202 my $res; 209 my $res;
203 210
204 for my $par (@$pars) { 211 for my $par (@$pars) {
205 if ($par->{type} =~ /^head\d+$/) { 212 if ($par->{type} =~ /^head\d+$/) {
206 $res .= "B<$par->{markup}>\n\n"; 213 $res .= "B<$par->{markup}>\n\n";
207 } elsif ($par->{type} eq "verbatim") { 214 } elsif ($par->{type} eq "verbatim") {
208 $res .= "\n$par->{markup}\n\n"; 215 $res .= "$par->{markup}\n\n";
209 } elsif ($par->{type} eq "item") { 216 } elsif ($par->{type} eq "item") {
210 $res .= "\n* I<$par->{markup}>\n\n"; 217 $res .= "* I<$par->{markup}>\n\n";
211 } else { 218 } else {
212 $res .= "$par->{markup}\n\n"; 219 $res .= "$par->{markup}\n\n";
213 } 220 }
214 } 221 }
215 222

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines