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.13 by root, Sun Aug 31 09:03:31 2008 UTC vs.
Revision 1.28 by root, Tue Nov 13 01:12:23 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines