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.32 by root, Sat Nov 17 23:40:02 2018 UTC

1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3#
4# Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5# Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6#
7# Deliantra is free software: you can redistribute it and/or modify it under
8# the terms of the Affero GNU General Public License as published by the
9# Free Software Foundation, either version 3 of the License, or (at your
10# option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the Affero GNU General Public License
18# and the GNU General Public License along with this program. If not, see
19# <http://www.gnu.org/licenses/>.
20#
21# The authors can be reached via e-mail to <support@deliantra.net>
22#
23
1package cf::pod; 24package cf::pod;
25
26use common::sense;
2 27
3use Pod::POM; 28use Pod::POM;
4 29
5our $indent; 30our $indent;
6our $level; 31our $level;
7our @result; 32our @result;
8 33
9package cf::pod::AsParagraphs; 34package cf::pod::AsParagraphs;
10 35
11use strict; 36use common::sense;
12 37
13use base "Pod::POM::View"; 38use base "Pod::POM::View";
14 39
40my %E = (
41 "<" => "E<lt>",
42 ">" => "E<gt>",
43);
44
15sub asxml($) { 45sub aspod($) {
16 local $_ = $_[0]; 46 local $_ = $_[0];
17 47
18 s/&/&amp;/g; 48 s/[<>]/$E{$1}/g;
19 s/>/&gt;/g;
20 s/</&lt;/g;
21 49
22 $_ 50 $_
23} 51}
24 52
25sub flatten($) { 53sub flatten($) {
26 local $_ = $_[0]; 54 local $_ = $_[0];
27 55
28 s/<[^>]+>//g;
29 s/^\s+//; 56 s/^\s+//;
30 s/\s+$//; 57 s/\s+$//;
31 s/\s+/ /g; 58 s/\s+/ /g;
32 59
33 $_ 60 $_
34} 61}
35 62
36*view_seq_file = 63*view_seq_file = sub { "C<$_[1]>" };
37*view_seq_code = 64*view_seq_code = sub { "C<$_[1]>" };
38*view_seq_bold = sub { "<b>$_[1]</b>" }; 65*view_seq_bold = sub { "B<$_[1]>" };
39*view_seq_italic = sub { "<i>$_[1]</i>" }; 66*view_seq_italic = sub { "I<$_[1]>" };
67*view_seq_T = sub { "T<$_[1]>" };
68*view_seq_G = sub { "G<$_[1]>" };
40*view_seq_zero = sub { }; 69*view_seq_zero = sub { "Z<>" };
41*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; 70*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
42*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 71*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
72#view_seq_entity
43 73
44sub view_seq_text { 74sub view_seq_text {
45 my $text = $_[1]; 75 my $text = $_[1];
46 $text =~ s/\s+/ /g; 76 $text =~ s/\s+/ /g;
47 asxml $text 77 aspod $text
48} 78}
49 79
50sub view_seq_link { 80sub view_seq_link {
51 my (undef, $link) = @_; 81 my (undef, $link) = @_;
52 82
53 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 83 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
54 84
55 if ($link =~ /http:/) { 85 if ($link =~ /http:/) {
56 "<u>" . (asxml $link) . "</u>" 86 "U<" . (aspod $link) . ">"
57 } else { 87 } else {
58 () 88 aspod $text
59 } 89 }
60} 90}
61 91
62sub view_item { 92sub view_item {
63 push @result, { 93 push @result, {
76sub view_verbatim { 106sub view_verbatim {
77 push @result, { 107 push @result, {
78 type => "verbatim", 108 type => "verbatim",
79 indent => $indent * 16, 109 indent => $indent * 16,
80 level => $level, 110 level => $level,
81 markup => asxml $_[1], 111 markup => $_[1],
82 }; 112 };
83 () 113 ()
84} 114}
85 115
86sub view_textblock { 116sub view_textblock {
164 194
165############################################################################# 195#############################################################################
166 196
167package cf::pod; 197package cf::pod;
168 198
169sub pom_as_paragraphs($) { 199sub pom_as_paragraphs_ng($) {
170 my ($pom) = @_; 200 my ($pom) = @_;
171 201
172 # we suckers use global variables, unfortunately. 202 # we suckers use global variables, unfortunately.
173 my $guard = cf::lock_acquire "cf::pod::as_paragraphs";
174
175 local $indent = 0; 203 local $indent = 0;
176 local $level = 1; 204 local $level = 1;
177 local @result = ( { } ); 205 local @result = ( { } );
178 206
179 $pom->present ("cf::pod::AsParagraphs"); 207 $pom->present ("cf::pod::AsParagraphs");
180 208
181 [grep $_->{index} || exists $_->{markup}, @result] 209 [grep $_->{index} || exists $_->{markup}, @result]
182} 210}
183 211
212sub pom_as_paragraphs($) {
213 my ($pom) = @_;
214
215 my $guard = cf::lock_acquire "cf::pod::as_paragraphs";
216
217 $pom->pom_as_paragraphs_ng
218}
219
184sub load_pod($) { 220sub load_pod($) {
185 my ($path) = @_; 221 my ($path) = @_;
186 222
187 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], 223 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
188 1 => sub { 224 9 => sub {
189 my ($src) = @_; 225 my ($src) = @_;
226
190 cf::fork_call { 227 cf::fork_call {
191 my $pod = $src->[0]; 228 Coro::Storable::blocking_nfreeze
192 utf8::decode $pod; 229 pom_as_paragraphs_ng
193 Coro::Storable::freeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) 230 +(Pod::POM->new->parse_text ($src->[0]))
194 } 231 }
195 }; 232 };
196} 233}
197 234
198# format as cfpod-style text 235# format as cfpod-style text
199sub as_text($) { 236sub as_cfpod($) {
200 my ($pars) = @_; 237 my ($pars) = @_;
201 238
202 my $res; 239 my $res;
203 240
204 for my $par (@$pars) { 241 for my $par (@$pars) {
205 if ($par->{type} =~ /^head\d+$/) { 242 if ($par->{type} =~ /^head\d+$/) {
206 $res .= "B<$par->{markup}>\n\n"; 243 $res .= "B<$par->{markup}>\n\n";
207 } elsif ($par->{type} eq "verbatim") { 244 } elsif ($par->{type} eq "verbatim") {
208 $res .= "\n$par->{markup}\n\n"; 245 $res .= "$par->{markup}\n\n";
209 } elsif ($par->{type} eq "item") { 246 } elsif ($par->{type} eq "item") {
210 $res .= "\n* I<$par->{markup}>\n\n"; 247 $res .= "* I<$par->{markup}>\n\n";
211 } else { 248 } else {
212 $res .= "$par->{markup}\n\n"; 249 $res .= "$par->{markup}\n\n";
213 } 250 }
214 } 251 }
215 252

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines