ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Pod.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Pod.pm (file contents):
Revision 1.22 by root, Sun Mar 30 11:31:09 2008 UTC vs.
Revision 1.24 by root, Sat Apr 3 02:58:25 2010 UTC

1package DC::Pod; 1package DC::Pod;
2 2
3use strict; 3use common::sense;
4use utf8;
5 4
6use Storable; 5use Storable;
7 6
8our $VERSION = 1.03; 7our $VERSION = 1.03;
9 8
40sub is_prefix_of($@) { 39sub 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
54sub find(@) { 52sub 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
69sub full_path_of($) { 68sub 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines