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