Skip to content

Commit 7a6cf0f

Browse files
committed
Explain Declarator blocks in language/pod
1 parent 006efcf commit 7a6cf0f

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

doc/Language/pod.pod6

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ A very simple Perl 6 Pod document
2222
=head1 Block Structure
2323
2424
A Pod document may consist of multiple Pod blocks.
25-
There are three ways to define a block; all of which yield the same result.
25+
There are four ways to define a block (delimited, paragraph, abbreviated, declarator);
26+
the first three yield the same result but the fourth differs.
2627
You can use whichever form is most convenient for your particular documentation task.
2728
2829
=head2 Delimited blocks
@@ -57,6 +58,42 @@ first blank line.
5758
=head1 Top Level Heading
5859
=end code
5960
61+
=head2 Declarator blocks
62+
63+
Declarator blocks differ from the others by not having a specific type,
64+
instead they are attached to some source code.
65+
66+
Declarator blocks are introduced by a special comment: either C<#=> or C<#|>,
67+
which must be immediately followed by either a space or an opening bracket.
68+
If followed by a space, the block is terminated by the end of line;
69+
if followed by one or more opening brackets, the block is terminated by the matching
70+
sequence of closing brackets.
71+
72+
Blocks starting with C<#|> are attached to the code after them,
73+
and blocks starting with C<#=> are attached to the code before them.
74+
75+
Since declarator blocks are attached to source code, they can be used to document
76+
classes, roles, subroutines etc.
77+
78+
The C<WHY> method can be used on these classes, roles, subroutines etc. to return the attached Pod value.
79+
80+
=begin code :skip-test
81+
#| Base class for magicians
82+
class Magician {
83+
has Int $.level;
84+
has Str @.spells;
85+
}
86+
87+
#| Fight mecanics
88+
sub duel(Magician $a, Magician $b) {
89+
}
90+
#= Magicians only, no mortals.
91+
92+
say Magician.WHY; # OUTPUT: «Base class for magicians␤»
93+
say &duel.WHY.leading; # OUTPUT: «Fight mecanics␤»
94+
say &duel.WHY.trailing; # OUTPUT: «Magicians only, no mortals.␤»
95+
=end code
96+
6097
=head1 Block types
6198
6299
Pod offers a wide range of standard block types.

0 commit comments

Comments
 (0)