> That's not right, is it? Or I don't understand what perl 6 does with
> the capturing parens that's different from perl 5. In perl 5 (and what
> I would expect from perl 6), @split would contain the following strings
> at the following array indices:
>
...
Your concern seems to be with the added test and your issues with
respect to that test are valid. A small change to the Any-str.pm/parrot
patch and a revised limit test are included with the updated attachments
that, I believe, address the noted problem(s).
Index: t/spec/S32-str/split-simple.t
===================================================================
--- t/spec/S32-str/split-simple.t (revision 26002)
+++ t/spec/S32-str/split-simple.t (working copy)
@@ -2,7 +2,7 @@
use Test;
# L<S29/Str/"=item split">
-plan 45;
+plan 46;
=begin description
@@ -83,12 +83,13 @@
# split should return capture
my @split = 'abc def ghi'.split(/(\s+)/);
-#?rakudo todo "split should return captures"
-#?DOES 3
-{
- ok @split.elems == 5, q{split returns captured delimiter} ;
- ok @split[1] eq ' ', q{split captured single space};
- ok @split[3] eq ' ', q{split captured multiple spaces};
-}
+ok @split.elems == 5, q{split returns captured delimiter} ;
+ok @split[1] eq ' ', q{split captured single space};
+ok @split[3] eq ' ', q{split captured multiple spaces};
+...@split = 'abc::def::ghi'.split(/(\:)/, 3);
+ok @split.elems == 5 and
+ @split[3] eq ':' and
+ @split[4] eq 'def::ghi',
+ q{split with capture obeyed limit};
# vim: ft=perl6
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm
index 27c2080..0346d4e 100644
--- a/src/setting/Any-str.pm
+++ b/src/setting/Any-str.pm
@@ -54,9 +54,23 @@ class Any is also {
my $s = ~self;
my $l = $limit ~~ Whatever ?? Inf !! $limit;
my $keep = '';
+
return gather {
while $l > 1 && $s ~~ $delimiter {
take $keep ~ $s.substr(0, $/.from);
+
+ # match objects too tied to underlying strings so copy ...
+ my @mat_cap = @().map: { substr($_, 0) };
+ my $mat_cap_n = $l min @mat_cap.elems;
+ if ($mat_cap_n) {
+ if $mat_cap_n == @mat_cap {
+ take @mat_cap
+ }
+ else {
+ take @mat_cap[ 0 .. ($mat_cap_n -1) ]
+ }
+ }
+
if $/.from == $/.to {
$keep = $s.substr($/.to, 1);
$s.=substr($/.to + 1);