.htmlgen/gen

filter: Statementstmt 62.8% 227 / 361 Branchbran 17.7% 11 / 62 Conditioncond 13.6% 3 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 69.1% 74 / 107 Podpod n/a totaltotal 55.7% 315 / 565 CC 41 SCAR 27.3
CC
41
Cov
54%
genfile
132.0
copyfiles
56.0
__ANON__
20.0
CRAP 15.4
« lib/FP/Repl/WithRepl.pm ↑ Summary lib/FP/Show.pm »
1 #!/usr/bin/env perl
2  
3 #
4 # Copyright (c) 2014-2021 Christian Jaeger, copying@christianjaeger.ch
5 #
6 # This is free software, offered under either the same terms as perl 5
7 # or the terms of the Artistic License version 2 or the terms of the
8 # MIT License (Expat version). See the file COPYING.md that came
9 # bundled with this file.
10 #
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use experimental "signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # find modules from functional-perl working directory (not installed)
18 1 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 our ($mydir, $myname);
20  
21 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.7
22 1 ▶ my $location = (-l $0) ? abs_path($0) : $0;
Branch: 1 branch
BranchTrueFalseTotal
-l $0 ? : 0 1 1
23 1 ▶ $location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
Branch: 1 branch
BranchTrueFalseTotal
$location =~ m[(.*?)([^/]+?)_?\z]s or die "?" 1 0 1
24 1 ($mydir, $myname) = ($1, $2);
25 }
26 1 ▶use lib "$mydir/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use lib "$mydir/../meta"; # for FunctionalPerl::Indexing
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # and the htmlgen/ directory
30 1 ▶use lib $mydir;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use FP::Docstring;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Chj::Backtrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Hash::Util 'lock_hash';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use Chj::xperlfunc qw(basename dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use Chj::xIOUtil qw(xgetfile_utf8 xcopyfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use FP::HashSet ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use PXML::XHTML ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use PXML::Serialize 'puthtmlfile';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use FP::Array ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use FP::Array_sort;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use FP::Ops qw(string_cmp real_cmp the_method cut_method);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use FP::Equal qw(equal);
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use FP::autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use Chj::TEST ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use FP::List qw(is_pair list);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use PXML::Util qw(pxml_map_elements_exhaustively);
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use FP::Hash ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use PXML::Tags qw(with_toc);
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use FP::Predicates qw(complement);
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use FP::Git::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use FunctionalPerl::Htmlgen::PathTranslate;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use FunctionalPerl::Htmlgen::PathUtil qw(path_add path_diff path0);
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use FunctionalPerl::Htmlgen::Cost;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use FunctionalPerl::Htmlgen::default_config qw($default_config);
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use FunctionalPerl::Htmlgen::FileUtil qw(existingpath_or create_parent_dirs);
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use FunctionalPerl::Htmlgen::MarkdownPlus qw(markdownplus_parse);
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use FP::Lazy;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use FunctionalPerl::Htmlgen::Mediawiki qw(mediawiki_prepare mediawiki_replace
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 mediawiki_rexpand);
63 1 ▶use PXML::Preserialize qw(pxmlpre);
Subroutine BEGIN: called CC=1 SCAR=0.0
64 1 ▶use FP::PureHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 1 ▶use FP::Equal qw(pointer_eq);
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 1 our $css_path = "htmlgen.css";
69  
70 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
71 0 print "$myname config inbase outbase
72  
73 config is the path to a Perl file ending in a hash with config
74 values, see functional-perl/website/gen-config.pl for an example.
75  
76 inbase needs to be a git working directory.
77  
78 Assumes that there is a file '$css_path', which is included in the
79 <head/> and copied to outbase.
80  
81 Options:
82 --repl open a repl instead of running the main action
83 --trap trap uncached exception in a repl (implied by --repl)
84  
85 ";
86 0 exit 1;
87 }
88  
89 1 our $verbose = 0;
90 1 our ($opt_repl, $opt_trap);
91 GetOptions(
92 "verbose" => \$verbose,
93 0 ▶ "help" => sub {usage},
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 1 ▶ "repl" => \$opt_repl,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("verbose", \$main::verbose, "help", sub { usage(); } , "repl", \$main::opt_repl, "trap", \$main::opt_trap) or exit 1 1 0 1
95 "trap" => \$opt_trap,
96 ) or exit 1;
97 1 ▶usage unless @ARGV == 3 or ($opt_repl and @ARGV >= 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV == 3 or $main::opt_repl and @ARGV >= 1 0 1 1
Condition16%1/6
@ARGV == 3 or $main::opt_repl and @ARGV >= 1
l!l&&r!l&&!r
100
$main::opt_repl and @ARGV >= 1
!ll&&!rl&&r
000
MC/DC0%0/3
@ARGV == 3 or $main::opt_repl and @ARGV >= 1
@ARGV == 3 $main::opt_repl @ARGV >= 1
Truth table25%1/4
A or B and C
A= @ARGV == 3B= $main::opt_replC= @ARGV >= 1
ABCresult
1XX1
0111
00X0
0100
98  
99 1 our ($configpath, $inbase, $outbase) = @ARGV;
100  
101 1 our $user_config = require $configpath;
102  
103 1 ▶require FP::Repl::Trap if $opt_trap;
Branch: 1 branch
BranchTrueFalseTotal
if $main::opt_trap 0 1 1
104  
105 1 our $config = hashset_union($user_config, $default_config);
106  
107 1 lock_hash %$config;
108  
109 1 our $pathtranslate = FunctionalPerl::Htmlgen::PathTranslate->new__(
110 subhash($config, "is_indexpath0", "downcaps"));
111  
112 1 our $gitrepository = FP::Git::Repository->new_(chdir => $inbase);
113  
114 0 ▶sub path0_to_inpath($path0) {
Subroutine path0_to_inpath: not called CC=1 SCAR=6.9
115 0 "$inbase/" . $path0
116 }
117  
118 0 ▶sub path0_to_outpath($path0) {
Subroutine path0_to_outpath: not called CC=1 SCAR=6.9
119  
120 #"$outbase/".$pathtranslate->xsuffix_md_to_html($path0,0)
121 # nope, also used for .pl file copying,
122 0 "$outbase/" . $pathtranslate->possibly_suffix_md_to_html($path0, 0)
123 }
124  
125 1 ▶use FunctionalPerl::Htmlgen::Toc;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 1 ▶use FunctionalPerl::Htmlgen::Linking;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 1 ▶use FunctionalPerl::Htmlgen::PerlTidy;
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 # XX make configurable
130  
131 # (This is getting a bit too layered now. Still Ok?)
132  
133 # normal simply gives a keyword arg based constructor that creates it
134 4 ▶sub normal($classname) {
Subroutine normal: called CC=1 SCAR=0.0
135 16 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
136 16 $classname->new_(@_)
137 }
138 4 }
139  
140 # This one adds in the functional_perl_base_dir argument:
141 1 ▶sub with_args ($classname, @args) {
Subroutine with_args: called CC=1 SCAR=0.0
142 4 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
143 4 $classname->new_(@_, @args)
144 }
145 1 }
146  
147 1 our $pxml_mappers =
148  
149 # These implement FunctionalPerl::Htmlgen::PXMLMapper; subarray
150 # for those that match on the same tagname, in order of preference
151 # (the chain exits once an element has been replaced).
152 [
153 normal("FunctionalPerl::Htmlgen::Linking::Anchors"),
154 normal("FunctionalPerl::Htmlgen::Toc"), # <with_toc>
155 [
156 normal("FunctionalPerl::Htmlgen::PerlTidy"),
157 with_args(
158 "FunctionalPerl::Htmlgen::Linking::code",
159  
160 # For names that we never want to auto-link as modules to
161 # CPAN since they are something else ("CPAN-exceptions"):
162  
163 # This directory is scanned for all sub definitions (not
164 # package names), including method names, and they are all
165 # excluded from being auto-linked to CPAN. (Note: this is
166 # relative to cwd which is set by website/gen to be inside
167 # website/; this is a hack, should be passed as an
168 # argument instead.)
169 functional_perl_base_dir => "..",
170  
171 # These names are also being ignored (things which do not
172 # exist as a subroutine but still shouldn't be linked):
173 static_ignore_names => [
174 qw( map tail grep head join test shift inverse Maybe
175 Just Nothing Int Integer undef let my our foo bar
176 baz sub return open all )
177 ]
178 )
179 ],
180 normal("FunctionalPerl::Htmlgen::Linking::a_href"),
181 ];
182  
183 4 ▶sub pxml_name_to_mapper(@PXMLMapper_args) {
Subroutine pxml_name_to_mapper: called CC=4 SCAR=14.9
184 purehash(
185 map {
186 4 ▶ my $ref = ref $_ or die "bug";
Branch: 1 branch
BranchTrueFalseTotal
my $ref = ref $_ or die "bug" 16 0 16
187 16 ▶ if (not $ref eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ref eq 'CODE') { } 4 12 16
188  
189 # subarray given (autobox coming into play; can be
190 # "ARRAY" or purearray depending on time...)
191 4 ▶ my $ms = $_->map(sub ($constr) { $constr->(@PXMLMapper_args) });
Subroutine __ANON__: called CC=1 SCAR=0.0
192 4 my $elnames = $ms->first->match_element_names;
193 $ms->rest->every(
194 4 ▶ sub($v) {
Subroutine __ANON__: called CC=1 SCAR=0.0
195 4 equal $elnames, $v->match_element_names
196 }
197 4 ▶ ) or die "not all have the same elnames";
Branch: 1 branch
BranchTrueFalseTotal
$ms->rest->every(sub ($v) { equal($elnames, $v->match_element_names); } ) or die "not all have the same elnames" 4 0 4
198  
199 # chain element $e through them until it was processed:
200 my $fn = $ms->fold_right(
201 8 ▶ sub ($m, $prev) {
Subroutine __ANON__: called CC=1 SCAR=5.1
202 0 ▶ sub ($e, $uplist) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
203  
204 #warn "checking out $m..";
205 0 my $e2 = $m->map_element($e, $uplist);
206 0 ▶ if (pointer_eq $e, $e2) {
Branch: 1 branch
BranchTrueFalseTotal
if (pointer_eq($e, $e2)) { } 0 0 0
207 0 &$prev($e, $uplist)
208 } else {
209 0 $e2
210 }
211 }
212 0 ▶ }, sub ($e, $uplist) {$e}
Subroutine __ANON__: not called CC=1 SCAR=1.2
213 4 );
214 4 map { ($_, $fn) } @$elnames
215 } else {
216  
217 # instantiate a mapper
218 12 my $m = $_->(@PXMLMapper_args);
219  
220 # register it for all the element names it wants to see
221 map {
222 17 ▶ ($_, sub { $m->map_element(@_) })
Subroutine __ANON__: called CC=1 SCAR=0.0
223 12 } @{ $m->match_element_names }
224 }
225 } @$pxml_mappers
226 )
227 }
228  
229 4 ▶sub default_pxml_name_to_mapper () {
Subroutine default_pxml_name_to_mapper: called CC=1 SCAR=2.6
230  
231 # fake instance for tests only
232 pxml_name_to_mapper(
233 path0 => "NOPATH",
234 0 ▶ maybe_have_path0 => sub { die "NOIMPL" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
235 0 ▶ perhaps_filename_to_path0 => sub { die "NOIMPL" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
236 4 pathtranslate => $pathtranslate
237 )
238 }
239  
240 4 ▶sub process_body (
Subroutine process_body: called CC=4 SCAR=14.1
241 $v,
242 4 $pxml_name_to_mapper = default_pxml_name_to_mapper(),
243 4 $mediawikitoken = "NOTOKEN",
244 $mediawikitable = {}
245 )
246 4 {
247 4 __ "([PXML::Element],..) -> [PXML::Element] "
248 . "-- applies the transformations in $pxml_mappers";
249  
250 # HACK: can't mediawiki_expand the whole document in string format
251 # before the markdown parsing, since it would expand examples in
252 # code sections as well. So instead leave the [[ ]] in (unharmed
253 # by markdown) and expand it here on individual text segments,
254 # then map it (and here comes the hacky part, you will forget to
255 # update here when prepending another mapping phase or so, right?)
256 # the same way the rest of the document is treated.
257  
258 18 ▶ my $map_text_mediawiki = sub ($v, $uplist) {
Subroutine __ANON__: called CC=3 SCAR=11.8
259  
260 # ($uplist might be empty in tests)
261 18 ▶ if (is_pair $uplist and $uplist->first->name eq "code") {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pair($uplist) and $uplist->first->name eq 'code') { } 0 18 18
Condition66%2/3
is_pair($uplist) and $uplist->first->name eq "code"
!ll&&!rl&&r
2160
MC/DC0%0/2
is_pair($uplist) and $uplist->first->name eq "code"
is_pair($uplist) $uplist->first->name eq "code"
Truth table66%2/3
A and B
A= is_pair($uplist)B= $uplist->first->name eq "code"
ABresult
0X0
100
111
262  
263 # don't expand it in code segments
264 0 mediawiki_replace($v, $mediawikitoken, $mediawikitable)
265 } else {
266 18 my $body = mediawiki_rexpand($v, $mediawikitoken, $mediawikitable);
267 array_map(
268 18 ▶ sub($e) {
Subroutine __ANON__: called CC=1 SCAR=0.0
269 18 pxml_map_elements_exhaustively($e, $pxml_name_to_mapper,
270 undef);
271 },
272 18 $body
273 )
274 }
275 4 };
276  
277 4 pxml_map_elements_exhaustively($v, $pxml_name_to_mapper,
278 $map_text_mediawiki)
279 }
280  
281 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
282 1 HTML(process_body(["Hello", WITH_TOC({ level => 1 }, H1 "world")]))->string
283 }
284 1 '<html>Hello<div class="toc_box"><dir class="toc"><h3 class="toc_title">Contents</h3><li><dir class="toc"><a href="#world">1. world</a></dir></li></dir></div><a name="world"><h1>1. world</h1></a></html>';
285  
286 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
287 1 HTML(process_body(["Hello", WITH_TOC ["some", H2 "world"]]))->string
288 }
289 1 '<html>Hello<div class="toc_box"><dir class="toc"><h3 class="toc_title">Contents</h3><li><dir class="toc"><a href="#world">1. world</a></dir></li></dir></div>some<a name="world"><h2>1. world</h2></a></html>';
290  
291 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
292 1 HTML(
293 process_body(
294 [
295 P("Hello"),
296 WITH_TOC { level => 1 },
297 [" ", P("blabla"), A({ name => "a" }, " ", DIV H1("for one")),]
298 ]
299 )
300 )->string
301 }
302 1 '<html><p>Hello</p><div class="toc_box"><dir class="toc"><h3 class="toc_title">Contents</h3><li><dir class="toc"><a href="#for_one">1. for one</a></dir></li></dir></div> <p>blabla</p><a name="a"> <div><a name="for_one"><h1>1. for one</h1></a></div></a></html>';
303  
304 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
305 1 HTML(
306 process_body(
307 [
308 P("Hello"),
309 WITH_TOC { level => 1 },
310 [
311 " ", P("blabla"), H1("for one"), H2("more one"),
312 TABLE(TR TD P("blah"), H1("sub two"), DIV("bla")),
313 ]
314 ]
315 )
316 )->string
317 }
318 1 '<html><p>Hello</p>'
319 . '<div class="toc_box"><dir class="toc"><h3 class="toc_title">Contents</h3><li><dir class="toc"><a href="#for_one">1. for one</a><li><dir class="toc"><a href="#more_one">1.1. more one</a></dir></li></dir></li><li><dir class="toc"><a href="#sub_two">2. sub two</a></dir></li></dir></div>'
320 . ' <p>blabla</p><a name="for_one"><h1>1. for one</h1></a><a name="more_one"><h2>1.1. more one</h2></a><table><tr><td><p>blah</p><a name="sub_two"><h1>2. sub two</h1></a><div>bla</div></td></tr></table></html>';
321  
322 # Note: the cost range feature is not used on the Functional Perl
323 # website. It could be used to connect issues to a cost for budgeting.
324  
325 1 package FunctionalPerl::Htmlgen::_::Genfilestate {
326 1 ▶ use FP::Docstring;
Subroutine BEGIN: called CC=1 SCAR=0.0
327  
328 1 ▶ use FP::Struct [
Subroutine BEGIN: called CC=1 SCAR=0.0
329 1 'filesinfo', 'groupedfiles', 'nonbugfiles',
330 'costranges', # path0 -> costrange-string; filled
331 # in by mutation when processing
332 # non-buglist groups
333 1 ];
334  
335 0 ▶ sub set_costrange ($self, $path0, $maybe_costrange) {
Subroutine set_costrange: not called CC=1 SCAR=6.9
336 0 __ '~ugly, mutates';
337 0 $$self{costranges}{$path0} = $maybe_costrange;
338 }
339  
340 0 ▶ sub costrange ($self, $path0) {
Subroutine costrange: not called CC=1 SCAR=6.9
341 0 $$self{costranges}{$path0}
342 }
343  
344 1 _END_
345 }
346  
347 1 package FunctionalPerl::Htmlgen::_::Filesinfo {
348 1 ▶ use FP::Hash "hash_perhaps_ref";
Subroutine BEGIN: called CC=1 SCAR=0.0
349 1 ▶ use FP::Array qw(array_to_hash_group_by);
Subroutine BEGIN: called CC=1 SCAR=0.0
350 1 ▶ use FunctionalPerl::Htmlgen::PathUtil qw(path_add path_diff path0);
Subroutine BEGIN: called CC=1 SCAR=0.0
351 1 ▶ use FP::PureArray;
Subroutine BEGIN: called CC=1 SCAR=0.0
352 1 ▶ use FP::Docstring;
Subroutine BEGIN: called CC=1 SCAR=0.0
353  
354 0 ▶ sub groupkey($path) {
Subroutine groupkey: not called CC=3 SCAR=24.8
355 0 __ 'a string key for grouping this path amongst other files, to '
356 . 'process them in an order that satisfies dependency on costranges';
357 0 my $p0 = path0 $path;
358 0 ▶ if ($p0 =~ m|^bugs/|) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p0 =~ m[^bugs/]) { } 0 0 0
elsif ($p0 =~ m[^docs/bugs.*\.md$]) { } 0 0 0
359 0 "bugs"
360 } elsif ($p0 =~ m|^docs/bugs.*\.md$|) {
361 0 "buglist"
362 } else {
363 0 "normal"
364 }
365 }
366  
367 1 ▶ use FP::Struct [
Subroutine BEGIN: called CC=1 SCAR=0.0
368 1 'files', 'filename_to_path0', 'all_path0_exists',
369 'path0_exists', # path0 => ()
370 'all_path0_used', # path0 => usecount, mutated
371 1 ];
372  
373 0 ▶ sub filename_to_path0 ($self, $filename) {
Subroutine filename_to_path0: not called CC=2 SCAR=17.9
374 0 ▶ $$self{filename_to_path0}{$filename}
Condition0%0/2
$self->{"filename_to_path0"}{$filename} // die("no mapping for filename '${filename}'")
l!l
00
MC/DC0%0/1
$self->{"filename_to_path0"}{$filename} // die("no mapping for filename '${filename}'")
$self->{"filename_to_path0"}{$filename}
Truth table0%0/2
A
A= $self->{"filename_to_path0"}{$filename}
Aresult
11
00
375 // die "no mapping for filename '$filename'"
376 }
377  
378 0 ▶ sub filename_to_maybe_path0 ($self, $filename) {
Subroutine filename_to_maybe_path0: not called CC=1 SCAR=6.9
379 0 $$self{filename_to_path0}{$filename}
380 }
381  
382 # still very unclear about the exact name styling. Prefer perhaps,
383 # and "then" also move the qualificator to the front? (but leave
384 # the one for hash_ where it is since hash_ is the type prefix?) :
385 0 ▶ sub perhaps_filename_to_path0 ($self, $filename) {
Subroutine perhaps_filename_to_path0: not called CC=1 SCAR=6.9
386 0 hash_perhaps_ref($$self{filename_to_path0}, $filename)
387 }
388  
389 0 ▶ sub all_path0_exists ($self, $path0) {
Subroutine all_path0_exists: not called CC=2 SCAR=17.9
390 defined $$self{all_path0_exists}{$path0}
391 0 ▶ or defined $$self{all_path0_exists}{ $path0 . "/" }
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"all_path0_exists"}{$path0} or defined $self->{"all_path0_exists"}{$path0 . '/'} 0 0 0
392 }
393  
394 0 ▶ sub path0_is_directory ($self, $path0) {
Subroutine path0_is_directory: not called CC=1 SCAR=6.9
395 0 $path0 =~ s|/+$||s;
396 0 defined $$self{all_path0_exists}{ $path0 . "/" }
397 }
398  
399 0 ▶ sub path0_exists ($self, $path0) {
Subroutine path0_exists: not called CC=1 SCAR=6.9
400 0 defined $$self{path0_exists}{$path0}
401 }
402  
403 0 ▶ sub all_path0_used_inc ($self, $path0) {
Subroutine all_path0_used_inc: not called CC=1 SCAR=6.9
404 0 __ '~ugly, mutates';
405 0 $$self{all_path0_used}{$path0}++
406 }
407  
408 0 ▶ sub new_genfilestate($self) {
Subroutine new_genfilestate: not called CC=2 SCAR=17.9
409 0 my $groupedfiles = array_to_hash_group_by $self->files, \&groupkey;
410  
411 0 my $nonbugfiles = purearray(@{ $$groupedfiles{normal} },
412 0 ▶ @{ $$groupedfiles{buglist} || [] });
Condition0%0/2
$groupedfiles->{'buglist'} || []
l!l
00
MC/DC0%0/1
$groupedfiles->{'buglist'} || []
$groupedfiles->{'buglist'}
Truth table0%0/2
A
A= $groupedfiles->{'buglist'}
Aresult
11
00
413  
414 0 FunctionalPerl::Htmlgen::_::Genfilestate->new(
415 $self, # just so as to bundle it up, too, ugly?
416 $groupedfiles, $nonbugfiles, {} # costranges (mutated)
417 )
418 }
419  
420 1 _END_
421 }
422  
423 0 ▶sub get_filesinfo () {
Subroutine get_filesinfo: not called CC=1 SCAR=6.9
424 0 __ '() -> Filesinfo '
425 . '-- read info about files from disk as immutable struct';
426  
427 0 my $all_files = $gitrepository->ls_files->array;
428  
429 0 my $files = array_filter(cut_method($pathtranslate, "is_md"), $all_files);
430  
431 0 my $filename_to_path0 = +{ map { basename($_) => path0($_) } @$files };
432  
433 my $all_path0_exists = +{
434 0 map { path0($_) => 1 } @$all_files,
435  
436 # and their directories, ok? Any directory that has files
437 # from git will be ok as link target, ok?
438 0 map { dirname($_) . "/" } @$all_files
439 };
440  
441 0 my $path0_exists = +{ map { path0($_) => 1 } @$files };
442  
443 0 FunctionalPerl::Htmlgen::_::Filesinfo->new(
444 $files, $filename_to_path0, $all_path0_exists, $path0_exists,
445 {}, # all_path0_used
446 )
447 }
448  
449 # Navigation:
450  
451 0 ▶sub nav_bar ($items_in_level, $item_selected, $viewed_at_item) {
Subroutine nav_bar: not called CC=1 SCAR=6.9
452 UL(
453 { class => "menu" },
454 $items_in_level->map_with_islast(
455 0 ▶ sub ($is_last, $item) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
456 0 my $filetitle = $pathtranslate->path0_to_title($item->path0);
457 0 my $is_viewed = equal($item, $viewed_at_item);
458 0 my $is_open = equal($item, $item_selected);
459  
460 0 ▶ LI(
Branch: 3 branches
BranchTrueFalseTotal
$is_last ? : 0 0 0
$is_viewed ? : 0 0 0
$is_open ? : 0 0 0
461 { class => ($is_last ? "menu_last" : "menu") },
462 (
463 $is_viewed
464 ? SPAN({ class => "menu_selected" }, $filetitle)
465 : A(
466 {
467 class => ($is_open ? "menu_open" : "menu"),
468 href => File::Spec->abs2rel(
469 $pathtranslate->xsuffix_md_to_html(
470 $item->path0, 0
471 ),
472 dirname($viewed_at_item->path0)
473 )
474 },
475 $filetitle
476 )
477 ),
478 " "
479 )
480 }
481 )
482 0 )
483 }
484  
485 # For access from main:: by the code in the configuration file (hacky):
486 1 ▶use FunctionalPerl::Htmlgen::Nav qw(_nav entry);
Subroutine BEGIN: called CC=1 SCAR=0.0
487  
488 1 ▶sub nav {
Subroutine nav: called CC=1 SCAR=0.0
489 1 _nav(list(@_), \&nav_bar)
490 }
491  
492 # /for access from main:: by the code in the configuration file.
493  
494 1 ▶our $HEAD = pxmlpre 3, sub ($title, $csspath, $user_additions) {
Subroutine __ANON__: called CC=1 SCAR=0.0
495 1 HEAD(TITLE($title),
496 LINK({ rel => "stylesheet", href => $csspath, type => "text/css" }),
497 $user_additions)
498 1 };
499  
500 0 ▶sub genfile ($path, $groupname, $genfilestate) {
Subroutine genfile: not called CC=11 SCAR=48.8
501 0 __ '($path, $groupname, $genfilestate) -> () '
502 . '-- convert markdown file at $path to xhtml file at '
503 . 'corresponding output path';
504  
505 0 my $path0 = path0 $path;
506 0 my $outpath = path0_to_outpath($path0);
507 0 mkdir dirname($outpath);
508  
509 0 my $filetitle = $pathtranslate->path0_to_title($path0);
510  
511 0 my $str = xgetfile_utf8 "$inbase/$path";
512  
513 0 ▶ if ($$config{warn_hint}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"warn_hint"}) 0 0 0
514 0 ▶ $str =~ s/^\(?Check the.*?website.*?---\s+//s
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^\(?Check the.*?website.*?---\s+//s or $path =~ m[COPYING|bugs|licenses/] or warn "'${path}' is missing hint" 0 0 0
Condition0%0/3
$str =~ s/^\(?Check the.*?website.*?---\s+//s or $path =~ m[COPYING|bugs|licenses/]
l!l&&r!l&&!r
000
MC/DC0%0/2
$str =~ s/^\(?Check the.*?website.*?---\s+//s or $path =~ m[COPYING|bugs|licenses/]
$str =~ s/^\(?Check the.*?website.*?---\s+//s $path =~ m[COPYING|bugs|licenses/]
Truth table0%0/3
A or B
A= $str =~ s/^\(?Check the.*?website.*?---\s+//sB= $path =~ m[COPYING|bugs|licenses/]
ABresult
1X1
011
000
515 or $path =~ /COPYING|bugs|licenses\//
516 or warn "'$path' is missing hint";
517 }
518  
519 0 ▶ if (my $hdl = $config->{path0_handlers}->{$path0}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hdl = $main::config->{"path0_handlers"}{$path0}) 0 0 0
520 0 $str = $hdl->($path, $path0, $str);
521 }
522  
523 0 my $maybe_costrange = do {
524  
525 # extract Cost indicators:
526 0 my $namere = qr/\w+/;
527 0 my $nameplusre = qr/\(?$namere\)?/;
528 0 ▶ my $possibly_nameplus_to_name = sub($maybe_nameplus) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
529 0 ▶ if (defined $maybe_nameplus) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maybe_nameplus) { } 0 0 0
530 0 ▶ my ($name) = $maybe_nameplus =~ qr/($namere)/ or die "bug";
Branch: 1 branch
BranchTrueFalseTotal
my($name) = $maybe_nameplus =~ qr/($namere)/ or die "bug" 0 0 0
531 0 $name
532 } else {
533 undef
534 0 }
535 0 };
536 0 local our $costs = [];
537 0 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\b[Cc]ost # name: parentheses for "library cost" (?:\s+($nameplusre))? : \s* # base costs ((?:$nameplusre\s*\+\s*)*) \s* # amount \$\s*(\d+) /gx) 0 0 0
538 $str =~ m{\b[Cc]ost
539 # name: parentheses for "library cost"
540 (?:\s+($nameplusre))?
541 :
542 \s*
543 # base costs
544 ((?:$nameplusre\s*\+\s*)*)
545 \s*
546 # amount
547 \$\s*(\d+)
548 }gx
549 )
550 {
551 0 my ($nameplus, $basecosts, $val) = ($1, $2, $3);
552 0 my $name = &$possibly_nameplus_to_name($nameplus);
553 my @basecosts
554 0 = map { &$possibly_nameplus_to_name($_) } split /\s*\+\s*/,
555 $basecosts;
556 0 ▶ push @$costs,
Condition0%0/3
$nameplus && $nameplus =~ /^\(/
!ll&&!rl&&r
000
MC/DC0%0/2
$nameplus && $nameplus =~ /^\(/
$nameplus $nameplus =~ /^\(/
Truth table0%0/3
A && B
A= $nameplusB= $nameplus =~ /^\(/
ABresult
0X0
100
111
557 new FunctionalPerl::Htmlgen::Cost::_::Cost($name,
558 (not $nameplus or not($nameplus =~ /^\(/)),
559 \@basecosts, $val);
560 }
561 0 ▶ @$costs
Branch: 1 branch
BranchTrueFalseTotal
@$main::costs ? : 0 0 0
562 ? FunctionalPerl::Htmlgen::Cost::_::Totalcost->new($costs)->range
563 : undef
564 };
565 0 ▶ if (defined $maybe_costrange) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maybe_costrange) 0 0 0
566 0 $genfilestate->set_costrange($path0, $maybe_costrange);
567 }
568  
569 0 my $mediawikitoken = rand; # not fork safe!
570 my ($h1, $body, $mediawikitable)
571 = markdownplus_parse($str,
572 0 ▶ lazy { $pathtranslate->path0_to_title($path0) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
573 0 $mediawikitoken);
574  
575 0 ▶ my $maybe_buglist = $groupname eq "buglist" && do {
Condition0%0/3
$groupname eq 'buglist' && do { my $bugs = array_sort(array_map(sub ($path) { my $path0 = path0($path); my $title = $pathtranslate->path0_to_title($path0); [$title, $path0, $genfilestate->costrange($path0)]; } , $genfilestate->groupedfiles->{'bugs'}), on(sub { $_[0][0]; } , \&main::string_cmp)); TABLE({'class', 'costlist'}, THEAD(TH('Type'), TH('Title'), TH('Cost range (USD)')), map({() = @$_; my $relurl = 'File::Spec'->abs2rel($main::pathtranslate->xsuffix_md_to_html($p0, 0), basename($path0)); TR(TD($main::pathtranslate->path0_to_bugtype($p0)), TD(A({'href', $relurl}, $title)), TD({'align', 'center'}, $costrange));} @$bugs)) }
!ll&&!rl&&r
000
MC/DC0%0/2
$groupname eq 'buglist' && do { my $bugs = array_sort(array_map(sub ($path) { my $path0 = path0($path); my $title = $pathtranslate->path0_to_title($path0); [$title, $path0, $genfilestate->costrange($path0)]; } , $genfilestate->groupedfiles->{'bugs'}), on(sub { $_[0][0]; } , \&main::string_cmp)); TABLE({'class', 'costlist'}, THEAD(TH('Type'), TH('Title'), TH('Cost range (USD)')), map({() = @$_; my $relurl = 'File::Spec'->abs2rel($main::pathtranslate->xsuffix_md_to_html($p0, 0), basename($path0)); TR(TD($main::pathtranslate->path0_to_bugtype($p0)), TD(A({'href', $relurl}, $title)), TD({'align', 'center'}, $costrange));} @$bugs)) }
$groupname eq 'buglist' do { my $bugs = array_sort(array_map(sub ($path) { my $path0 = path0($path); my $title = $pathtranslate->path0_to_title($path0); [$title, $path0, $genfilestate->costrange($path0)]; } , $genfilestate->groupedfiles->{'bugs'}), on(sub { $_[0][0]; } , \&main::string_cmp)); TABLE({'class', 'costlist'}, THEAD(TH('Type'), TH('Title'), TH('Cost range (USD)')), map({() = @$_; my $relurl = 'File::Spec'->abs2rel($main::pathtranslate->xsuffix_md_to_html($p0, 0), basename($path0)); TR(TD($main::pathtranslate->path0_to_bugtype($p0)), TD(A({'href', $relurl}, $title)), TD({'align', 'center'}, $costrange));} @$bugs)) }
Truth table0%0/3
A && B
A= $groupname eq 'buglist'B= do { my $bugs = array_sort(array_map(sub ($path) { my $path0 = path0($path); my $title = $pathtranslate->path0_to_title($path0); [$title, $path0, $genfilestate->costrange($path0)]; } , $genfilestate->groupedfiles->{'bugs'}), on(sub { $_[0][0]; } , \&main::string_cmp)); TABLE({'class', 'costlist'}, THEAD(TH('Type'), TH('Title'), TH('Cost range (USD)')), map({() = @$_; my $relurl = 'File::Spec'->abs2rel($main::pathtranslate->xsuffix_md_to_html($p0, 0), basename($path0)); TR(TD($main::pathtranslate->path0_to_bugtype($p0)), TD(A({'href', $relurl}, $title)), TD({'align', 'center'}, $costrange));} @$bugs)) }
ABresult
0X0
100
111
576 my $bugs = array_sort(
577 array_map(
578 0 ▶ sub($path) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
579 0 my $path0 = path0 $path;
580 0 my $title = $pathtranslate->path0_to_title($path0);
581 0 [$title, $path0, $genfilestate->costrange($path0)]
582 },
583 $genfilestate->groupedfiles->{bugs}
584 ),
585 0 ▶ on sub { $_[0][0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
586 0 \&string_cmp # XX not a good cmp.
587 );
588  
589 TABLE(
590 { class => "costlist" },
591 THEAD(TH("Type"), TH("Title"), TH("Cost range (USD)")),
592 map {
593 0 my ($title, $p0, $costrange) = @$_;
594 0 my $relurl
595 = File::Spec->abs2rel(
596 $pathtranslate->xsuffix_md_to_html($p0, 0),
597 basename($path0));
598 0 TR(
599 TD($pathtranslate->path0_to_bugtype($p0)),
600 TD(A({ href => $relurl }, $title)),
601 TD({ align => "center" }, $costrange)
602 )
603 } @$bugs
604 )
605 };
606  
607 0 my $filesinfo = $genfilestate->filesinfo;
608 my $pxml_name_to_mapper = pxml_name_to_mapper(
609 path0 => $path0,
610 0 ▶ maybe_have_path0 => sub($path0) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
611 0 ▶ if ($filesinfo->all_path0_exists($path0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filesinfo->all_path0_exists($path0)) { } 0 0 0
612 0 $filesinfo->all_path0_used_inc($path0);
613 0 $path0
614 } else {
615 undef
616 0 }
617 },
618 0 ▶ perhaps_filename_to_path0 => sub($filename) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
619 0 $filesinfo->perhaps_filename_to_path0($filename)
620 },
621 0 map_code_body => hash_maybe_ref($config, "map_code_body"),
622 pathtranslate => $pathtranslate,
623 );
624  
625 0 my $nav = $$config{nav};
626 0 my $nav_index = $nav->index;
627  
628 # ^ this could be cached across all documents (but measurements
629 # haves shown it to be insignificant)
630 0 my $nav_upitems = $nav_index->path0_to_upitems($path0);
631 0 my $nav_self = $nav_upitems->first;
632  
633 my $html = HTML(
634 &$HEAD(
635 [$config->{title}->($filetitle)],
636 scalar path_diff($path0, $css_path),
637 scalar $config->{head}->($path0)
638 ),
639 BODY(
640 $config->{header}->($path0),
641  
642 (
643 1
644 ?
645  
646 # make the top nav level contain all unknown pages
647 # (and don't include pages declared in the nav that
648 # don't exist)
649 (
650 $nav->nav_bar_level0(
651 $genfilestate->nonbugfiles->map (
652 0 ▶ sub($p0) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
653 0 $nav_index->path0_to_item($p0)
654 }
655 ),
656 $nav_upitems->last,
657 $nav_upitems->first
658 ),
659  
660 $nav->nav_bar_levels($nav_self, $nav_upitems)->rest
661 )
662 :
663  
664 # strictly follow the navigation declaration
665 $nav->nav_bar_levels($nav_self, $nav_upitems)
666 ),
667  
668 $config->{belownav}->($path0),
669 $h1,
670 process_body(
671 $body, $pxml_name_to_mapper,
672 $mediawikitoken, $mediawikitable
673 ),
674 $maybe_buglist,
675 BR, HR,
676 (
677 $maybe_costrange
678 ? P("\x{21d2} Cost range: \$", $maybe_costrange)
679 : ()
680 ),
681 DIV({ class => "footer_date" }, $gitrepository->author_date($path)),
682 0 ▶ $config->{footer}->($path0)
Branch: 1 branch
BranchTrueFalseTotal
$maybe_costrange ? : 0 0 0
683 )
684 );
685  
686 0 puthtmlfile($outpath, $html);
687 }
688  
689 0 ▶sub genfiles($filesinfo) {
Subroutine genfiles: not called CC=3 SCAR=24.8
690 0 my $genfilestate = $filesinfo->new_genfilestate;
691 0 for my $groupname (qw(bugs normal buglist)) {
692 0 for (@{ $genfilestate->groupedfiles->{$groupname} }) {
693 0 genfile $_, $groupname, $genfilestate
694 }
695 }
696 }
697  
698 # copy referenced non-.md files:
699 0 ▶sub copyfiles($filesinfo) {
Subroutine copyfiles: not called CC=7 SCAR=40.3
700 0 for my $path0 (
701 hashset_keys hashset_union(
702 $filesinfo->all_path0_used,
703 array_to_hashset(hash_ref_or($config, "copy_paths", []))
704 )
705 )
706 {
707 0 ▶ next if $filesinfo->path0_exists($path0); # md path
Branch: 1 branch
BranchTrueFalseTotal
if $filesinfo->path0_exists($path0) 0 0 0
708 0 ▶ next if $filesinfo->path0_is_directory($path0);
Branch: 1 branch
BranchTrueFalseTotal
if $filesinfo->path0_is_directory($path0) 0 0 0
709 0 create_parent_dirs($path0, \&path0_to_outpath);
710 0 xcopyfile(path0_to_inpath($path0), path0_to_outpath($path0));
711 }
712 0 ▶ if (my ($separate) = hash_perhaps_ref($config, "copy_paths_separate")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($separate) = hash_perhaps_ref($main::config, "copy_paths_separate")) 0 0 0
713 0 for my $root (keys %$separate) {
714 0 for my $path0 (@{ $$separate{$root} }) {
715 0 xcopyfile "$root/$path0", path0_to_outpath $path0
716 }
717 }
718 }
719  
720 # copy htmlgen CSS file
721 xcopyfile(
722 0 existingpath_or(
723 path0_to_inpath($css_path),
724 path0_to_inpath("htmlgen/$css_path")
725 ),
726 path0_to_outpath($css_path)
727 );
728 }
729  
730 0 ▶sub main () {
Subroutine main: not called CC=1 SCAR=6.9
731 0 mkdir $outbase;
732 0 warn "running get_filesinfo..";
733 0 my $filesinfo = get_filesinfo;
734 0 warn "running genfiles..";
735 0 genfiles($filesinfo);
736 0 warn "running copyfiles..";
737 0 copyfiles($filesinfo);
738 }
739  
740 1 ▶perhaps_run_tests __PACKAGE__ or do {
Branch: 1 branch
BranchTrueFalseTotal
perhaps_run_tests(__PACKAGE__) or do { $main::opt_repl ? do { require FP::Repl; require FP::Repl::Trap; FP::Repl::repl() } : main() } 1 0 1
741 $opt_repl
742 0 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
$main::opt_repl ? : 0 0 0
743 0 require FP::Repl;
744 0 require FP::Repl::Trap;
745 0 FP::Repl::repl();
746 }
747 : main;
748 };
749  
« lib/FP/Repl/WithRepl.pm ↑ Summary lib/FP/Show.pm »