Skip to content

Commit cabada6

Browse files
authored
Merge pull request #9 from tbrowder/next-ver
Update description and other documentation
2 parents 61bbc3a + 2a00642 commit cabada6

File tree

8 files changed

+152
-14
lines changed

8 files changed

+152
-14
lines changed

Changes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Revision history for Pod-TreeWalker
22

33
{{$NEXT}}
4+
- Enabled creation of a separate document for the Listener
5+
role from existing pod in file
6+
'lib/Pod/TreeWalker/Listener.rakumod'.
7+
- Updated copyright date in file
8+
'lib/Pod/TreeWalker/Listener.rakumod'.
9+
- Added a short example of actual use along with other
10+
README.md tweaks.
11+
- Added missing dep 'Test::Coverage' to META6.json
12+
- Adjusted Test::Coverage numbers in xt/
413

514
0.0.5 2025-05-06T11:02:12+02:00
615
- Changed trait 'is built' to 'is required' on the Listener

Listener.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+

META6.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"TREE"
2424
],
2525
"test-depends": [
26+
"Test::Coverage"
2627
],
2728
"version": "0.0.5"
2829
}

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,38 @@ SYNOPSIS
1111
```raku
1212
use Pod::TreeWalker;
1313

14-
my $to-html = Pod::To::HTML.new(...);
15-
Pod::TreeWalker.new( :listener($to-html) ).walk-pod($=pod);
14+
my $L = My::Listener.new;
15+
my $o = Pod::TreeWalker.new: :listener($L);
16+
my @events = $o.walk-pod($=pod);
1617
```
1718

1819
DESCRIPTION
1920
===========
2021

2122
This class provides an API for walking a pod tree (as provided by `$=pod`). Each node in the tree will trigger one or more events. These events cause methods to be called on a listener object that you provide. This lets you do something with a Pod document without having to know much about the underlying tree structure of Pod.
2223

24+
Note: Use distribution `Pod::Load` for an easy way to access the Pod from a file or a string.
25+
2326
METHODS
2427
=======
2528

2629
new
2730
---
2831

2932
```raku
30-
my $walker = Pod::TreeWalker.new( :listener($object) )
33+
my $walker = Pod::TreeWalker.new: :listener($object);
3134
```
3235

33-
The constructor requires a single named argument `:listener`. This object must implement the [Pod::TreeWalker::Listener](./t/lib/TestListener.rakumod) API as demonstrated in file './t/lib/TestListener.rakumod'.
36+
The constructor requires a single named argument `:listener`. This object must implement the `Pod::TreeWalker::Listener` API as demonstrated in file './t/lib/TestListener.rakumod'. See more details in **Listener.md**.
3437

3538
walk-pod
3639
--------
3740

3841
```raku
39-
$walker.walk-pod($pod);
42+
my @events = $walker.walk-pod($pod);
4043
```
4144

42-
This method walks through a pod tree starting with the top node in `$pod`. You can provide either an array of pod nodes (as stored in `$=pod`) or a single top-level node (such as `$=pod[0]`).
45+
This method walks through a pod tree starting with the top node in `$pod`. You can provide either an array of pod nodes (as stored in `$=pod`) or a single top-level node (such as `$=pod[0]`). The `@events` list provides the details of each pod node encountered.
4346

4447
text-content-of
4548
---------------

dist.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ filename = doc/Pod-TreeWalker.rakudoc
1515
provider = github-actions/linux.yml
1616
provider = github-actions/macos.yml
1717
provider = github-actions/windows.yml
18+
19+
[RunAfterBuild]
20+
cmd = raku --doc=Markdown lib/Pod/TreeWalker/Listener.rakumod > Listener.md

doc/Pod-TreeWalker.rakudoc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Pod::TreeWalker - Walk a Pod tree and generate an event for each node
1010

1111
use Pod::TreeWalker;
1212

13-
my $to-html = Pod::To::HTML.new(...);
14-
Pod::TreeWalker.new( :listener($to-html) ).walk-pod($=pod);
13+
my $L = My::Listener.new;
14+
my $o = Pod::TreeWalker.new: :listener($L);
15+
my @events = $o.walk-pod($=pod);
1516

1617
=end code
1718

@@ -23,31 +24,36 @@ cause methods to be called on a listener object that you provide. This lets
2324
you do something with a Pod document without having to know much about the
2425
underlying tree structure of Pod.
2526

27+
Note: Use distribution C<Pod::Load> for an easy way to access the Pod
28+
from a file or a string.
29+
2630
=head1 METHODS
2731

2832
=head2 new
2933

3034
=begin code :lang<raku>
3135

32-
my $walker = Pod::TreeWalker.new( :listener($object) )
36+
my $walker = Pod::TreeWalker.new: :listener($object);
3337

3438
=end code
3539

3640
The constructor requires a single named argument C<:listener>. This object must
37-
implement the L<Pod::TreeWalker::Listener|./t/lib/TestListener.rakumod> API
41+
implement the C<Pod::TreeWalker::Listener> API
3842
as demonstrated in file './t/lib/TestListener.rakumod'.
43+
See more details in B<Listener.md>.
3944

4045
=head2 walk-pod
4146

4247
=begin code :lang<raku>
4348

44-
$walker.walk-pod($pod);
49+
my @events = $walker.walk-pod($pod);
4550

4651
=end code
4752

4853
This method walks through a pod tree starting with the top node in
4954
C<$pod>. You can provide either an array of pod nodes (as stored in C<$=pod>)
5055
or a single top-level node (such as C<$=pod[0]>).
56+
The C<@events> list provides the details of each pod node encountered.
5157

5258
=head2 text-content-of
5359

lib/Pod/TreeWalker/Listener.rakumod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Dave Rolsky
142142
143143
Copyright 2015 - 2018 Dave Rolsky
144144
145-
Copyright 2019 - 2022 Raku Community
145+
Copyright 2019 - 2025 Raku Community
146146
147147
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
148148

xt/coverage.rakutest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use Test::Coverage;
22

33
plan 2;
44

5-
coverage-at-least 81;
5+
coverage-at-least 80;
66

7-
uncovered-at-most 14;
7+
uncovered-at-most 15;
88

99
source-with-coverage;
1010

0 commit comments

Comments
 (0)