1
1
# !/usr/bin/env perl6
2
2
use v6 ;
3
+ use File::Find;
3
4
4
5
my $ index_file = " index.data" ;
5
6
multi sub MAIN () {
@@ -9,14 +10,21 @@ multi sub MAIN() {
9
10
10
11
multi sub MAIN (' index' ) {
11
12
my % words ;
12
- for dir(' lib' ) -> $ file {
13
- my $ pod = substr ($ file . Str , 0 , $ file . Str . chars -4 );
13
+
14
+ my @ files := find(: dir(' lib' ),: type(' file' ));
15
+
16
+ for @ files -> $ f {
17
+ my $ file = $ f . path ;
14
18
next if $ file ! ~~ /\. pod$ /;
19
+ my $ pod = substr ($ file . Str , 0 , $ file . Str . chars -4 );
20
+ $ pod .= subst (/lib\ // ," " );
21
+ $ pod .= subst (/\ // ,' ::' ,: g);
15
22
my $ section = ' ' ;
16
- for open (' lib/ ' ~ $ file . Str ). lines -> $ row {
23
+ for open ( $ file . Str ). lines -> $ row {
17
24
# if $row ~~ /^\=(item|head\d) \s+ X\<(.*)\> \s*$/ {
18
25
if $ row ~~ /^ \=(item| head\d ) \s + (.*? ) \s * $ / {
19
26
$ section = $1 . Str ;
27
+ $ section .= subst (/\| /," " ,: g);
20
28
% words {$ section }. push ([$ pod , $ section ]);
21
29
}
22
30
if $ row ~~ /X\<( .*? )\> / and $ section {
@@ -43,3 +51,14 @@ multi sub MAIN('list') {
43
51
}
44
52
}
45
53
54
+ multi sub MAIN (' lookup' , $ key ) {
55
+ if $ index_file . IO ~~ : e {
56
+ my % data = EVAL slurp $ index_file ;
57
+ die " not found" unless % data {$ key };
58
+ say % data {$ key }. split (" " ). [0 ];
59
+ } else {
60
+ say " First run $ * PROGRAM_NAME index to create the index" ;
61
+ exit ;
62
+ }
63
+ }
64
+
0 commit comments