NAME Pod::Utils - Set of helper functions to ease working with Pods!
use Pod ::Utils;# time to work with Pod::* elements!say first-subtitle($ = pod [0 ]. contents);= begin pod = SUBTITLE Some cool text = end pod Pod::Utils is a set of routines that help you to deal with Pod elements.It lets you manipulate several kinds of Pod objects, obtain gists and modifyheadings.
sub first-code-block (Array @ pod )returns Str ;Returns the firstPod::Block::Code
found in an array, concatenating all lines in it.If none is found, it will return an empty string.
Example:
= begin pod = begin code say "some code"; say "more code"; = end code = end pod first-code-block($ = pod [0 ]. contents)# OUTPUT «say "some code";say "more code";»sub first-title (Array @ pod )returns Pod ::Block::Named;Returns the first=TITLE
element found in@pods
.
Example:
= begin pod = TITLE title = end pod first-title($ = pod [0 ]. contents)# OUTPUT equivalent to:= TITLE title sub first-subtitle (Array @ pod )returns Pod ::Block::Named;Returns the first=SUBTITLE
element found in@pods
.
Example:
= begin pod = subTITLE subtitle = end pod first-subtitle($ = pod [0 ]. contents)# OUTPUT equivalent to:= SUBTITLE subtitle multi textify-guts (Any : U , )return Str ;multi textify-guts (Str : D \v)return Str ;multi textify-guts (List : D \v)return Str ;multi textify-guts (Pod ::Block \v)return Str ;Converts lists ofPod::Block::*
objects andPod::Block
objects to strings.
Example:
my $ block = Pod ::Block::Para. new (contents => [" block" ]);say textify-guts($ block );# OUTPUT «block»say textify-guts([$ block ,$ block ]);# OUTPUT «block block»multi sub recurse-until-str multi sub recurse-until-str (Str : D $ s )return Str ;multi sub recurse-until-str (Pod ::Block$ n )return Str ;Accepts aPod::Block::*
object and returns a concatenation of all subpods content.
Example:
my $ block = Pod ::Block::Para. new (contents => [" block" ]);my $ complex-block = pod-block(" one" , pod-block(" two" ), pod-bold(" three" ));say recurse-until-str($ block );# OUTPUT «block»say recurse-until-str($ complex-block );# OUTPUT «onetwothree»use Pod ::Utils::Build;# time to build Pod::* elements!say pod-bold(" bold text" );Pod::Utils::Build is a set of routines that help you to create newPod elements.
sub pod-title (Str $ title ,)returns Pod ::Block::Named;Creates a newPod::Block::Named
object (with:name
set to"TITLE"
)and populates it with aPod::Block::Para
containing$title
.
Example:
pod-title(" title" );# OUTPUT Equivalent to:= begind pod = TITLE title = end pod sub pod-with-title (Str $ title ,Array @ blocks )returns Pod ::Block::Named;Creates a newPod::Block::Named
object (with:name
set to "pod")and populate it with a title (usingpod-title
) and@blocks
.
Example:
= begind pod Normal paragraph= end pod pod-with-title(" title" ,$ = pod . first . contents[0 ]);# OUTPUT Equivalent to:= beging pod = TITLE title Normal paragraph= end pod sub pod-block (Array * @ contents )returns Pod ::Block::Para;Creates aPod::Block::Para
with contents set to@contents
.
Example:
say pod-block(" title" ,Pod ::Block::Para. new (contents => [" paragraph" ]));# OUTPUTPod ::Block::Para titlePod ::Block::Para paragraphsub pod-link (Str $ text ,Str $ url )returns Pod ::FormattingCode;Creates aPod::FormattingCode
(type Link) with contents set to$text
.and meta set to$url
.
Example:
pod-link(" text" ," url" );# OUTPUT Equivalent to: L<text|url > sub pod-bold (Str $ text ,)returns Pod ::FormattingCode;Creates aPod::FormattingCode
(type B) with contents set to$text
.
Example:
pod-bold(" text" );# OUTPUT Equivalent to: B<text > sub pod-code (Str $ text ,)returns Pod ::FormattingCode;Creates aPod::FormattingCode
(type C) with contents set to$text
.
Example:
pod-code(" text" );# OUTPUT Equivalent to: C<text > sub pod-item (Array * @ contents ,Int : $ level = 1 ,)returns Pod ::Item;Creates aPod::Item
object with contents set to@contents
and level to$level
.
Example:
pod-item(pod-block(" item" ),level => 1 );# OUTPUT Equivalent to:= item item sub pod-heading (Str $ name ,Int : $ level = 1 ,)returns Pod ::Heading;Creates aPod::Heading
object with level set$level
and contents initializedwith aPod::Block::Para
object containing$name
.
Example:
pod-heading(" heading" ,level => 1 );# OUTPUT Equivalent to:= head1 heading sub pod-table (Array @ contents ,Array : @ headers ,)returns Pod ::Block::Table;Creates aPod::Block::Table
object with the headers@headers
and rows@contents
.$caption
is set to""
.Example:
pod-table([[" col1" ," col2" ],],headers => [" h1" ," h2" ]);# OUTPUT Equivalent to:= begin table h1 | h2 ============ col1 | col2 = end table sub pod-lower-headings (Array @ content ,Int : $ to ,)returns Array ;Given an array of Pod objects, lower the level of every heading followingthe next formula =>current-level - $by + $to
, where$by
is the level of thefirst heading found in the array.
Example:
my @ contents = [ pod-heading(" head" ,level => 2 ), pod-heading(" head" ,level => 3 )];pod-lower-headings(@ contents )# OUTPUT Equivalent to:= head1 head = head2 head Alexander Mouquin <@Mouq>
Will Coleda <@coke>
Rob Hoelz <@hoelzro>
<@timo>
Moritz Lenz <@moritz>
Juan Julián <@JJ>
<@MasterDuke17>
Zoffix Znet <@zoffixznet>
Antonio <@antoniogamiz>
Copyright 2019 Perl 6 team
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.