Skip to content

Commit 4eaa349

Browse files
committed
fix index building and add simple key look
1 parent 9cb4baa commit 4eaa349

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

index.p6

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env perl6
22
use v6;
3+
use File::Find;
34

45
my $index_file = "index.data";
56
multi sub MAIN() {
@@ -9,14 +10,21 @@ multi sub MAIN() {
910

1011
multi sub MAIN('index') {
1112
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;
1418
next if $file !~~ /\.pod$/;
19+
my $pod = substr($file.Str, 0 , $file.Str.chars -4);
20+
$pod.=subst(/lib\//,"");
21+
$pod.=subst(/\//,'::',:g);
1522
my $section = '';
16-
for open('lib/' ~ $file.Str).lines -> $row {
23+
for open( $file.Str).lines -> $row {
1724
#if $row ~~ /^\=(item|head\d) \s+ X\<(.*)\> \s*$/ {
1825
if $row ~~ /^\=(item|head\d) \s+ (.*?) \s*$/ {
1926
$section = $1.Str;
27+
$section.=subst(/\|/,"",:g);
2028
%words{$section}.push([$pod, $section]);
2129
}
2230
if $row ~~ /X\<(.*?)\>/ and $section {
@@ -43,3 +51,14 @@ multi sub MAIN('list') {
4351
}
4452
}
4553

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

Comments
 (0)