Skip to content

Commit a034431

Browse files
committed
merge p6doc and p6doc-index, add dep
1 parent ce49e90 commit a034431

File tree

3 files changed

+80
-88
lines changed

3 files changed

+80
-88
lines changed

META6.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"perl" : "6.*",
33
"name" : "p6doc",
4-
"version" : "1.001001",
4+
"version" : "1.001002",
55
"description" : "Perl 6 documentation (tools and docs)",
66
"license" : "Artistic-2.0",
77
"depends" : [ "URI", "File::Temp", "JSON::Fast", "Pod::To::BigPage", "Pod::To::HTML",
8-
"OO::Monitors", "IO::String" ],
8+
"OO::Monitors", "IO::String", "File::Find" ],
99
"build-depends" : [ "File::Find" ],
1010
"provides" : {
1111
"Perl6::Type" : "lib/Perl6/Type.pm",

bin/p6doc

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env perl6
2-
use MONKEY-SEE-NO-EVAL; # until we have a better serialisation
2+
3+
use v6;
34
use JSON::Fast;
5+
use File::Find;
6+
use MONKEY-SEE-NO-EVAL; # until we have a better serialisation
47

58
my $PROGRAM-NAME = "p6doc";
69

@@ -71,7 +74,17 @@ sub show-docs(Str $path, :$section, :$no-pager) {
7174
}
7275

7376
sub USAGE() {
74-
say 'What documentation do you want to read?';
77+
say "You want to maintain the index?";
78+
say "To build an index for '$PROGRAM-NAME -f'";
79+
say " $PROGRAM-NAME build";
80+
say "\nTo list the index keys";
81+
say " $PROGRAM-NAME list";
82+
say "\nTo display module name(s) containing key";
83+
say " $PROGRAM-NAME lookup";
84+
say "\nTo show where the index file lives";
85+
say " $PROGRAM-NAME path-to-index";
86+
87+
say "\nWhat documentation do you want to read?";
7588
say "Examples: $PROGRAM-NAME Str";
7689
say " $PROGRAM-NAME Str.split";
7790
say " $PROGRAM-NAME faq";
@@ -85,7 +98,7 @@ sub USAGE() {
8598
say " $PROGRAM-NAME -f Type::Array.push";
8699

87100
say "\nYou can bypass the pager and print straight to stdout:";
88-
say " $PROGRAM-NAME -n Str"
101+
say " $PROGRAM-NAME -n Str";
89102
}
90103

91104
multi sub MAIN($docee, Bool :$n) {
@@ -120,7 +133,7 @@ multi sub MAIN($docee, Bool :$f!, Bool :$n) {
120133
show-docs($m, :section($method), :no-pager($n));
121134
} else {
122135
say 'In order to use unqualified sub and method names like "p6doc -f say"';
123-
say 'you will need to run "p6doc-index build" to build index.data.';
136+
say 'you will need to run "p6doc build" to build index.data.';
124137
say 'Otherwise use "p6doc -f Type::Str.split" instead of "p6doc -f split" for now.';
125138
exit 2;
126139
}
@@ -134,6 +147,67 @@ multi sub MAIN(Str $file where $file.IO ~~ :e, Bool :$n) {
134147
show-docs($file, :no-pager($n));
135148
}
136149

150+
# index related
151+
152+
multi sub MAIN('path-to-index') {
153+
say INDEX if INDEX.IO.e;
154+
}
155+
156+
multi sub MAIN('build') {
157+
my %words;
158+
159+
# XXX should index more than this - currently only core pod
160+
for ($*REPO.repo-chain()>>.Str X~ "{$*SPEC.dir-sep}doc{$*SPEC.dir-sep}").grep: *.IO.d -> $lib_path is copy {
161+
162+
# for p6doc -f only looking under "Type" directory is useful (and faster)
163+
my @files = find(:dir($lib_path ~ "Type"),:type('file')).map({.IO});
164+
165+
for @files -> $f {
166+
my $file = $f.path;
167+
next if $file !~~ /\.pod6?$/;
168+
my $pod = substr($file.Str, 0 , $file.Str.chars -4);
169+
$pod.=subst($lib_path,"");
170+
$pod.=subst(/"{$*SPEC.dir-sep}"/,'::',:g);
171+
my $section = '';
172+
for open( $file.Str).lines -> $row {
173+
if $row ~~ /^\=(item|head\d) \s+ (.*?) \s*$/ {
174+
$section = $1.Str if $1.defined;
175+
%words{$section}.push([$pod, $section]) if $section ~~ m/^("method "|"sub "|"routine ")/;
176+
}
177+
}
178+
}
179+
}
180+
181+
my $out = open(INDEX, :w);
182+
$out.print(%words.perl);
183+
$out.close;
184+
}
185+
186+
multi sub MAIN('list') {
187+
if INDEX.IO ~~ :e {
188+
my %data = EVAL slurp INDEX;
189+
for %data.keys.sort -> $name {
190+
say $name
191+
# my $newdoc = %data{$docee}[0][0] ~ "." ~ %data{$docee}[0][1];
192+
# return MAIN($newdoc, :f);
193+
}
194+
} else {
195+
say "First run $*PROGRAM-NAME build to create the index";
196+
exit;
197+
}
198+
}
199+
200+
multi sub MAIN('lookup', $key) {
201+
if INDEX.IO ~~ :e {
202+
my %data = EVAL slurp INDEX;
203+
die "not found" unless %data{$key};
204+
say %data{$key}.split(" ").[0];
205+
} else {
206+
say "First run $*PROGRAM-NAME build to create the index";
207+
exit;
208+
}
209+
}
210+
137211
sub disambiguate-f-search($docee, %data) {
138212
my %found;
139213

bin/p6doc-index

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)