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