Skip to content

Commit

Permalink
recurse-until-str added, documented and tested #1 #2 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogamiz committed Jun 25, 2019
1 parent 2cab7e9 commit e117272
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions lib/Pod/Utilities.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions t/15-recurse-until-str.t
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e117272

Please sign in to comment.