1 |
root |
1.2 |
package cf::pod; |
2 |
|
|
|
3 |
root |
1.20 |
use common::sense; |
4 |
|
|
|
5 |
root |
1.3 |
use Pod::POM; |
6 |
|
|
|
7 |
root |
1.2 |
our $indent; |
8 |
|
|
our $level; |
9 |
|
|
our @result; |
10 |
|
|
|
11 |
|
|
package cf::pod::AsParagraphs; |
12 |
|
|
|
13 |
root |
1.20 |
use common::sense; |
14 |
root |
1.2 |
|
15 |
|
|
use base "Pod::POM::View"; |
16 |
|
|
|
17 |
root |
1.15 |
my %E = ( |
18 |
|
|
"<" => "E<lt>", |
19 |
|
|
">" => "E<gt>", |
20 |
|
|
); |
21 |
|
|
|
22 |
root |
1.14 |
sub aspod($) { |
23 |
root |
1.2 |
local $_ = $_[0]; |
24 |
|
|
|
25 |
root |
1.15 |
s/[<>]/$E{$1}/g; |
26 |
root |
1.2 |
|
27 |
|
|
$_ |
28 |
|
|
} |
29 |
|
|
|
30 |
root |
1.5 |
sub flatten($) { |
31 |
|
|
local $_ = $_[0]; |
32 |
|
|
|
33 |
|
|
s/^\s+//; |
34 |
|
|
s/\s+$//; |
35 |
|
|
s/\s+/ /g; |
36 |
|
|
|
37 |
|
|
$_ |
38 |
|
|
} |
39 |
|
|
|
40 |
root |
1.17 |
*view_seq_file = sub { "C<$_[1]>" }; |
41 |
|
|
*view_seq_code = sub { "C<$_[1]>" }; |
42 |
root |
1.13 |
*view_seq_bold = sub { "B<$_[1]>" }; |
43 |
|
|
*view_seq_italic = sub { "I<$_[1]>" }; |
44 |
root |
1.19 |
*view_seq_T = sub { "T<$_[1]>" }; |
45 |
|
|
*view_seq_G = sub { "G<$_[1]>" }; |
46 |
root |
1.14 |
*view_seq_zero = sub { "Z<>" }; |
47 |
root |
1.2 |
*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; |
48 |
|
|
*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; |
49 |
|
|
|
50 |
|
|
sub view_seq_text { |
51 |
|
|
my $text = $_[1]; |
52 |
|
|
$text =~ s/\s+/ /g; |
53 |
root |
1.14 |
aspod $text |
54 |
root |
1.2 |
} |
55 |
|
|
|
56 |
|
|
sub view_seq_link { |
57 |
|
|
my (undef, $link) = @_; |
58 |
|
|
|
59 |
|
|
my $text = $link =~ s/^(.*)\|// ? $1 : $link; |
60 |
|
|
|
61 |
|
|
if ($link =~ /http:/) { |
62 |
root |
1.15 |
"U<" . (aspod $link) . ">" |
63 |
root |
1.2 |
} else { |
64 |
|
|
() |
65 |
|
|
} |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
sub view_item { |
69 |
|
|
push @result, { |
70 |
root |
1.5 |
type => "item", |
71 |
root |
1.2 |
indent => $indent * 8, |
72 |
|
|
level => $level, |
73 |
|
|
}; |
74 |
|
|
my $title = $_[1]->title->present ($_[0]); |
75 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
76 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
77 |
root |
1.2 |
local $level = $level + 1; |
78 |
|
|
$_[1]->content->present ($_[0]); |
79 |
|
|
() |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
sub view_verbatim { |
83 |
|
|
push @result, { |
84 |
root |
1.5 |
type => "verbatim", |
85 |
root |
1.2 |
indent => $indent * 16, |
86 |
|
|
level => $level, |
87 |
root |
1.13 |
markup => $_[1], |
88 |
root |
1.2 |
}; |
89 |
|
|
() |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
sub view_textblock { |
93 |
|
|
push @result, { |
94 |
|
|
indent => $indent * 16, |
95 |
|
|
level => $level, |
96 |
root |
1.6 |
markup => flatten $_[1], |
97 |
root |
1.2 |
}; |
98 |
|
|
() |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
sub view_head1 { |
102 |
|
|
push @result, { |
103 |
root |
1.5 |
type => "head1", |
104 |
root |
1.2 |
indent => $indent * 16, |
105 |
|
|
level => $level, |
106 |
|
|
}; |
107 |
|
|
my $title = $_[1]->title->present ($_[0]); |
108 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
109 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
110 |
root |
1.2 |
local $level = $level + 1; |
111 |
|
|
$_[1]->content->present ($_[0]); |
112 |
|
|
() |
113 |
|
|
}; |
114 |
|
|
|
115 |
|
|
sub view_head2 { |
116 |
|
|
push @result, { |
117 |
root |
1.5 |
type => "head2", |
118 |
root |
1.2 |
indent => $indent * 16, |
119 |
|
|
level => $level, |
120 |
|
|
}; |
121 |
|
|
my $title = $_[1]->title->present ($_[0]); |
122 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
123 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
124 |
root |
1.2 |
local $level = $level + 1; |
125 |
|
|
$_[1]->content->present ($_[0]); |
126 |
|
|
() |
127 |
|
|
}; |
128 |
|
|
|
129 |
|
|
sub view_head3 { |
130 |
|
|
push @result, { |
131 |
root |
1.5 |
type => "head3", |
132 |
root |
1.2 |
indent => $indent * 16, |
133 |
|
|
level => $level, |
134 |
|
|
}; |
135 |
|
|
my $title = $_[1]->title->present ($_[0]); |
136 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
137 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
138 |
root |
1.2 |
local $level = $level + 1; |
139 |
|
|
$_[1]->content->present ($_[0]); |
140 |
|
|
() |
141 |
|
|
}; |
142 |
|
|
|
143 |
|
|
sub view_over { |
144 |
|
|
local $indent = $indent + $_[1]->indent; |
145 |
|
|
push @result, { indent => $indent }; |
146 |
|
|
$_[1]->content->present ($_[0]); |
147 |
|
|
() |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
sub view_for { |
151 |
|
|
if ($_[1]->format eq "image") { |
152 |
|
|
# push @result, { |
153 |
|
|
# indent => $indent * 16, |
154 |
|
|
# level => $level, |
155 |
|
|
# markup => (::special image => "pod/" . $_->text), |
156 |
|
|
# }; |
157 |
|
|
} |
158 |
|
|
() |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
sub view_begin { |
162 |
|
|
() |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
sub view { |
166 |
|
|
my ($self, $type, $item) = @_; |
167 |
|
|
|
168 |
|
|
$item->content->present ($self); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
############################################################################# |
172 |
|
|
|
173 |
|
|
package cf::pod; |
174 |
|
|
|
175 |
root |
1.3 |
sub pom_as_paragraphs($) { |
176 |
root |
1.2 |
my ($pom) = @_; |
177 |
|
|
|
178 |
|
|
# we suckers use global variables, unfortunately. |
179 |
|
|
my $guard = cf::lock_acquire "cf::pod::as_paragraphs"; |
180 |
|
|
|
181 |
|
|
local $indent = 0; |
182 |
|
|
local $level = 1; |
183 |
|
|
local @result = ( { } ); |
184 |
|
|
|
185 |
|
|
$pom->present ("cf::pod::AsParagraphs"); |
186 |
|
|
|
187 |
|
|
[grep $_->{index} || exists $_->{markup}, @result] |
188 |
|
|
} |
189 |
|
|
|
190 |
root |
1.3 |
sub load_pod($) { |
191 |
|
|
my ($path) = @_; |
192 |
|
|
|
193 |
root |
1.4 |
Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], |
194 |
root |
1.18 |
7 => sub { |
195 |
root |
1.4 |
my ($src) = @_; |
196 |
root |
1.12 |
|
197 |
root |
1.5 |
cf::fork_call { |
198 |
root |
1.4 |
my $pod = $src->[0]; |
199 |
|
|
utf8::decode $pod; |
200 |
root |
1.12 |
Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) |
201 |
root |
1.4 |
} |
202 |
|
|
}; |
203 |
root |
1.3 |
} |
204 |
|
|
|
205 |
root |
1.8 |
# format as cfpod-style text |
206 |
root |
1.11 |
sub as_cfpod($) { |
207 |
root |
1.6 |
my ($pars) = @_; |
208 |
|
|
|
209 |
|
|
my $res; |
210 |
|
|
|
211 |
|
|
for my $par (@$pars) { |
212 |
|
|
if ($par->{type} =~ /^head\d+$/) { |
213 |
root |
1.8 |
$res .= "B<$par->{markup}>\n\n"; |
214 |
root |
1.6 |
} elsif ($par->{type} eq "verbatim") { |
215 |
root |
1.16 |
$res .= "$par->{markup}\n\n"; |
216 |
root |
1.6 |
} elsif ($par->{type} eq "item") { |
217 |
root |
1.16 |
$res .= "* I<$par->{markup}>\n\n"; |
218 |
root |
1.6 |
} else { |
219 |
root |
1.8 |
$res .= "$par->{markup}\n\n"; |
220 |
root |
1.6 |
} |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
$res |
224 |
|
|
} |
225 |
|
|
|
226 |
root |
1.2 |
1; |
227 |
|
|
|