Skip to content

Commit 2ca51ac

Browse files
committed
distiniguish subs and methods, if we can
1 parent e9b61ab commit 2ca51ac

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

htmlify.pl

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ ($pod)
6565
}
6666
}
6767

68+
sub first-code-block(@pod) {
69+
if @pod[1] ~~ Pod::Block::Code {
70+
return @pod[1].content.grep(Str).join;
71+
}
72+
'';
73+
}
74+
6875
sub MAIN(Bool :$debug, Bool :$typegraph = False) {
6976
$*DEBUG = $debug;
7077
for '', <type language routine images op op/prefix op/postfix op/infix
@@ -195,10 +202,24 @@ (Bool :$debug, Bool :$typegraph = False)
195202
say "$podname.$name" if $*DEBUG;
196203
next if $name ~~ /\s/;
197204
%methods-by-type{$podname}.push: $chunk;
205+
# deterimine whether it's a sub or method
206+
my Str $subkind;
207+
{
208+
my %counter;
209+
for first-code-block($chunk).lines {
210+
if ms/^ 'multi'? (sub|method)»/ {
211+
%counter{$0}++;
212+
}
213+
}
214+
if %counter == 1 {
215+
($subkind,) = %counter.keys;
216+
}
217+
}
218+
198219
$dr.add-new(
199220
:kind<routine>,
200-
# TODO: determine subkind, ie method/sub
201-
:name($name),
221+
:$subkind,
222+
:$name,
202223
:pod($chunk),
203224
:!pod-is-complete,
204225
:origin($d),
@@ -372,7 +393,7 @@ (Bool :$debug, Bool :$typegraph = False)
372393
});
373394
my %seen;
374395
@items.push: $dr.lookup('routine', :by<kind>).grep({!%seen{.name}++}).sort(*.name).map({
375-
"\{ label: \"Routine: {.name}\", value: \"{.name}\", url: \"{ fix-url(.url) }\" \}"
396+
"\{ label: \"{ (.subkind // 'Routine').tclc }: {.name}\", value: \"{.name}\", url: \"{ fix-url(.url) }\" \}"
376397
});
377398

378399
my $items = @items.join(",\n");
@@ -467,8 +488,13 @@ (Bool :$debug, Bool :$typegraph = False)
467488
sub write-routine-file($dr, $name) {
468489
say "Writing html/routine/$name.html" if $*DEBUG;
469490
my @docs = $dr.lookup($name, :by<name>).grep(*.kind eq 'routine');
470-
my $pod = pod-with-title("Documentation for routine $name",
471-
pod-block("Documentation for routine $name, assembled from the
491+
my $subkind = 'routine';
492+
{
493+
my @subkinds = @docs>>.subkind;
494+
$subkind = @subkinds[0] if all(@subkinds>>.defined) && [eq] @subkinds;
495+
}
496+
my $pod = pod-with-title("Documentation for $subkind $name",
497+
pod-block("Documentation for $subkind $name, assembled from the
472498
following types:"),
473499
@docs.map({
474500
pod-heading(.origin.name ~ '.' ~ .name),

0 commit comments

Comments
 (0)