1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
use strict;
sub WalkTree
{
my $tree = shift; # a Pod::Tree object
my $root = $tree->get_root; # the root node of the tree
WalkNode($root);
}
sub WalkNode
{
my $node = shift;
my $type = $node->get_type;
for ($type)
{
/root/ and WalkRoot ($node), last;
/verbatim/ and WalkVerbatim($node), last;
/ordinary/ and WalkOrdinary($node), last;
/command/ and WalkCommand ($node), last;
/sequence/ and WalkSequence($node), last;
/text/ and WalkText ($node), last;
/list/ and WalkList ($node), last;
/item/ and WalkItem ($node), last;
/for/ and WalkFor ($node), last;
}
}
sub WalkRoot
{
my $node = shift;
WalkChildren($node);
}
sub WalkVerbatim
{
my $node = shift;
my $text = $node->get_text;
}
sub WalkOrdinary
{
my $node = shift;
WalkChildren($node);
}
sub WalkCommand
{
my $node = shift;
my $command = node->get_command;
WalkChildren($node);
}
sub WalkSequence
{
my $node = shift;
my $letter = node->get_letter;
is_link $node and do
{
my $target = $node->get_target;
my $page = $target->get_page;
my $section = $target->get_section;
};
WalkChildren($node);
}
sub WalkText
{
my $node = shift;
my $text = $node->get_text;
}
sub WalkList
{
my $node = shift;
my $indent = $node->get_arg;
my $list_type = $node->get_list_type;
for ($list_type)
{
/bullet/ and last;
/number/ and last;
/text/ and last;
}
WalkChildren($node); # text of the =over paragraph
WalkSiblings($node); # items in the list
}
sub WalkItem
{
my $node = shift;
my $item_type = $node->get_list_type;
for ($item_type) # could be different from $list_type
{
/bullet/ and last;
/number/ and last;
/text/ and last;
}
WalkChildren($node); # text of the =item paragraph
}
sub WalkFor
{
my $node = shift;
my $formatter = $node->get_arg;
my $text = $node->get_text;
}
sub WalkChildren
{
my $node = shift;
my $children = $node->get_children;
for my $child (@$children)
{
WalkNode($child);
}
}
sub WalkSiblings
{
my $node = shift;
my $siblings = $node->get_siblings;
for my $sibling (@$siblings)
{
WalkNode($sibling);
}
}
|