package CFPlus::Pod; use strict; use Storable; our $VERSION = 1; our %wiki; *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; sub is_prefix_of($@) { my ($node, @path) = @_; return 1 unless @path; my $kw = pop @path; $node = $node->{parent} or return 0; return ! ! grep $_ eq $kw, @{ $node->{kw} }; } sub find(@) { my (@path) = @_; return unless @path; my $kw = pop @path; # TODO: make sure results are unique grep { is_prefix_of $_, @path } map @$_, $kw eq "*" ? @wiki{sort keys %wiki} : grep $_, $wiki{$kw} } sub full_path_of($) { my ($node) = @_; my $path = $node->{kw}[0]; $path = "$node->{kw}[0]/$path" while $node = $node->{parent}; $path } sub section_of($) { my ($node) = @_; my $doc = $node->{doc}; my $par = $node->{par}; my $lvl = $node->{level}; my @res; do { my $p = $doc->[$par]; if (exists $p->{markup}) { my %para = ( markup => $p->{markup}, indent => $p->{indent}, ); for (@{ $p->{widget} || [] }) { my ($class, @args) = @$_; push @{ $para{widget} }, $class->new (@args); } push @res, \%para; } } while $doc->[++$par]{level} > $lvl; @res } sub section(@) { map section_of $_, &find } sub as_label(@) { join "\n", map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, @_ } 1