Skip to content

Commit bc1661e

Browse files
committed
Short introduction to Pod introspection.
See issue #1907
1 parent 0728d80 commit bc1661e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

doc/Language/pod.pod6

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,51 @@ multi MAIN(Bool :$man)
574574
575575
Now C<myprogram --man> will output your Pod rendered as a man page.
576576
577+
578+
=head1 Accessing Pod
579+
580+
In order to access Pod documentation from within a program
581+
it is required to use the special C<=> twigil, as documented
582+
in the L<variables section|/language/variables#The_=_Twigil>.
583+
584+
The C<=> twigil provides the introspection over the Pod structure,
585+
providing a L<Pod::Block> tree root from which it is possible
586+
to access the whole structure of the Pod document.
587+
588+
As an example, the following piece of code instrospects
589+
its own Pod documentaion:
590+
591+
=begin code
592+
=begin pod
593+
594+
=head1 This is an head1 title
595+
596+
This is a paragraph.
597+
598+
=begin code
599+
'Hello World'.say;
600+
=end code
601+
602+
=end pod
603+
604+
for $=pod -> $pod-item {
605+
for $pod-item.contents -> $pod-block {
606+
$pod-block.perl.say;
607+
}
608+
}
609+
=end code
610+
611+
producing the following output:
612+
613+
=for code
614+
Pod::Heading.new(level => 1, config => {},
615+
contents => [Pod::Block::Para.new(config => {},
616+
contents => ["This is an head1 title"])])
617+
Pod::Block::Para.new(config => {}, contents => ["This is a paragraph."])
618+
Pod::Block::Code.new(allowed => [], config => {},
619+
contents => ["'Hello World'.say;", "\n"])
620+
621+
577622
=end pod
578623

579624
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)