|
| 1 | +NAME |
| 2 | +==== |
| 3 | + |
| 4 | +Pod::TreeWalker::Listener - Role for classes which handle events produced by Pod::TreeWalker |
| 5 | + |
| 6 | +SYNOPSIS |
| 7 | +======== |
| 8 | + |
| 9 | +```raku |
| 10 | +class MyListener does Pod::TreeWalker::Listener { |
| 11 | + multi method start(Pod::Heading $node --> False) { |
| 12 | + say "Heading level {$node.level}"; |
| 13 | + } |
| 14 | + |
| 15 | + multi method end( Pod::Heading $node --> False) { |
| 16 | + say "Heading level {$node.level}"; |
| 17 | + } |
| 18 | + |
| 19 | + method table-row (Array $row) { ... } |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +DESCRIPTION |
| 24 | +=========== |
| 25 | + |
| 26 | +This role defines the API which objects passed to `Pod::TreeWalker`'s constructor are expected to implement. |
| 27 | + |
| 28 | +METHODS TO BE IMPLEMENTED |
| 29 | +========================= |
| 30 | + |
| 31 | +start |
| 32 | +----- |
| 33 | + |
| 34 | +```raku |
| 35 | +$listener.start(... $node --> False) |
| 36 | +``` |
| 37 | + |
| 38 | +The `start` method is a multi method which is called for most Pod objects. It is passed a [doc:Pod::Block](doc:Pod::Block) object of some sort. |
| 39 | + |
| 40 | +If this method returns `False`, then the `Pod::TreeWalker` will not look at the contents of the node, nor will it call the corresponding `end` method for the node. |
| 41 | + |
| 42 | +### Tables |
| 43 | + |
| 44 | +The headers of a table (from `$node.headers`) are passed as an array of [Pod::Blocks](Pod::Blocks). |
| 45 | + |
| 46 | +end |
| 47 | +--- |
| 48 | + |
| 49 | +```raku |
| 50 | +$listener.end( ... $node --> False) |
| 51 | +``` |
| 52 | + |
| 53 | +The `end` is a multi method that is called for most Pod objects. It is passed a `Pod::Block` object of some sort. |
| 54 | + |
| 55 | +start-list |
| 56 | +---------- |
| 57 | + |
| 58 | +```raku |
| 59 | +$listener.start-list(Int :$level, Bool :numbered) |
| 60 | +``` |
| 61 | + |
| 62 | +This method is called whenever a new list level is encountered. It can be called multiple times in a row if a list item is introduced that skips levels, for example: |
| 63 | + |
| 64 | + =item1 start-list is called once |
| 65 | + =item3 start-list is called twice |
| 66 | + |
| 67 | +end-list |
| 68 | +-------- |
| 69 | + |
| 70 | +```raku |
| 71 | +$listener.end-list(Int :$level, Bool :numbered) |
| 72 | +``` |
| 73 | + |
| 74 | +This method is called whenever a list level is done. List `start-list`, it can be called multiple times in a row. |
| 75 | + |
| 76 | +table-row |
| 77 | +--------- |
| 78 | + |
| 79 | +```raku |
| 80 | +$listener.table-row(Array $row) |
| 81 | +``` |
| 82 | + |
| 83 | +This method is called once for each row in a table. Each element of `$row` will in turn be a [Pod::Block](Pod::Block). |
| 84 | + |
| 85 | +config |
| 86 | +------ |
| 87 | + |
| 88 | +```raku |
| 89 | +$listener.config(Pod::Config $node --> False) |
| 90 | +``` |
| 91 | + |
| 92 | +This method is called for Pod config declarations. |
| 93 | + |
| 94 | +text |
| 95 | +---- |
| 96 | + |
| 97 | +```raku |
| 98 | +$listener.text(Str $text) |
| 99 | +``` |
| 100 | + |
| 101 | +This method is called for plain text, usually inside a paragraph block. |
| 102 | + |
| 103 | +AUTHOR |
| 104 | +====== |
| 105 | + |
| 106 | +Dave Rolsky |
| 107 | + |
| 108 | +COPYRIGHT AND LICENSE |
| 109 | +===================== |
| 110 | + |
| 111 | +Copyright 2015 - 2018 Dave Rolsky |
| 112 | + |
| 113 | +Copyright 2019 - 2025 Raku Community |
| 114 | + |
| 115 | +This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0. |
| 116 | + |
0 commit comments