From e11727296c45b22e761dde84df02a345d00e1279 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 25 Jun 2019 20:26:19 +0200 Subject: [PATCH] recurse-until-str added, documented and tested #1 #2 #3 --- README.md | 19 +++++++++++++++++++ lib/Pod/Utilities.pm6 | 4 ++++ t/15-recurse-until-str.t | 15 +++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 t/15-recurse-until-str.t diff --git a/README.md b/README.md index e3f46a9..dbce849 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,25 @@ say textify-guts($block); # OUTPUT «block␤» say textify-guts([$block, $block]); # OUTPUT «block block␤» ``` +### multi sub recurse-until-str + +```perl6 +multi sub recurse-until-str(Str:D $s) return Str; +multi sub recurse-until-str(Pod::Block $n) return Str; + +``` + +Accepts a `Pod::Block::*` object and returns a concatenation of all subpods content. + +Example: + +```perl6 +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␤» +``` + # AUTHORS Alexander Mouquin <@Mouq> diff --git a/lib/Pod/Utilities.pm6 b/lib/Pod/Utilities.pm6 index 6b011de..7c5e0ee 100644 --- a/lib/Pod/Utilities.pm6 +++ b/lib/Pod/Utilities.pm6 @@ -115,4 +115,8 @@ multi textify-guts (Pod::Block \v) is export { pod2text v; } +#| Accepts a Pod::Block and returns a concatenation of all subpods content +multi sub recurse-until-str(Str:D $s) is export { $s } +multi sub recurse-until-str(Pod::Block $n) is export { $n.contents>>.&recurse-until-str().join } + # vim: expandtab shiftwidth=4 ft=perl6 diff --git a/t/15-recurse-until-str.t b/t/15-recurse-until-str.t new file mode 100644 index 0000000..eb54e3e --- /dev/null +++ b/t/15-recurse-until-str.t @@ -0,0 +1,15 @@ +use v6.c; +use Test; + +plan *; + +use Pod::Utilities; + +my $block = Pod::Block::Para.new(contents => ["block"]); +my $complex-block = pod-block("one", pod-block("two"), pod-bold("three")); + +is recurse-until-str("string") , "string" , "String not affected"; +is recurse-until-str($block) , "block" , "Single block"; +is recurse-until-str($complex-block), "onetwothree" , "Complex block"; + +done-testing; \ No newline at end of file