1 | package DC::Pod; |
1 | package DC::Pod; |
2 | |
2 | |
3 | use strict; |
3 | use common::sense; |
4 | use utf8; |
|
|
5 | |
4 | |
6 | use Storable; |
5 | use Storable; |
7 | |
6 | |
8 | our $VERSION = 1.03; |
7 | our $VERSION = 1.03; |
9 | |
8 | |
… | |
… | |
40 | sub is_prefix_of($@) { |
39 | sub is_prefix_of($@) { |
41 | my ($node, @path) = @_; |
40 | my ($node, @path) = @_; |
42 | |
41 | |
43 | return 1 unless @path; |
42 | return 1 unless @path; |
44 | |
43 | |
45 | my $kw = lc pop @path; |
44 | my $kw = pop @path; |
46 | |
45 | |
47 | $node = $node->[N_PARENT] |
46 | $node = $node->[N_PARENT] |
48 | or return 0; |
47 | or return 0; |
49 | |
48 | |
50 | #TODO: maybe get rid of lowercasing? |
|
|
51 | return scalar grep lc eq $kw, @{ $node->[N_KW] }; |
49 | return scalar grep $_ eq $kw, @{ $node->[N_KW] }; |
52 | } |
50 | } |
53 | |
51 | |
54 | sub find(@) { |
52 | sub find(@) { |
55 | my (@path) = @_; |
53 | my (@path) = @_; |
56 | |
54 | |
57 | return unless @path; |
55 | return unless @path; |
58 | |
56 | |
59 | my $kw = lc pop @path; |
57 | my $kw = pop @path; |
60 | |
58 | |
61 | # TODO: make sure results are unique |
59 | my %res = map +($_, $_), |
62 | |
|
|
63 | grep { is_prefix_of $_, @path } |
60 | grep { is_prefix_of $_, @path } |
64 | map @$_, |
61 | map @$_, |
65 | $kw eq "*" ? @wiki{sort keys %wiki} |
62 | $kw eq "*" ? values %wiki |
66 | : $wiki{$kw} || () |
63 | : $wiki{$kw} || (); |
|
|
64 | |
|
|
65 | values %res |
67 | } |
66 | } |
68 | |
67 | |
69 | sub full_path_of($) { |
68 | sub full_path_of($) { |
70 | my ($node) = @_; |
69 | my ($node) = @_; |
71 | |
70 | |
72 | my @path; |
71 | my @path; |
73 | |
72 | |
74 | # skip toplevel hierarchy pod/, because its not a document |
|
|
75 | while ($node->[N_PARENT]) { |
73 | while ($node) { |
76 | unshift @path, $node; |
74 | unshift @path, $node; |
77 | $node = $node->[N_PARENT]; |
75 | $node = $node->[N_PARENT]; |
78 | } |
76 | } |
79 | |
77 | |
80 | @path |
78 | @path |