Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and test that Mojo::ByteStream split method uses core split function semantics #1617

Closed
wants to merge 1 commit into from

Conversation

Grinnz
Copy link
Contributor

@Grinnz Grinnz commented Nov 28, 2020

Summary

The first argument to Mojo::ByteStream's split method has some special treatment as it's passed directly to the split function. Add some documentation and examples to clarify this treatment - it's the pattern argument and is treated as a regex, except in the awk compatibility special case of a single space character, and the special case of an empty pattern which splits on each character.

It also may be worthwhile to suggest and document passing split patterns to this function as qr// regex refs rather than strings, thoughts? (this is already tested)

Motivation

Clarify how this argument is interpreted.

References

https://perldoc.perl.org/functions/split

kraih
kraih previously approved these changes Nov 28, 2020
@kraih kraih requested a review from a team November 28, 2020 20:30
@Grinnz
Copy link
Contributor Author

Grinnz commented Nov 28, 2020

The split function only consistently interprets a string containing a single space when it's not a literal since 5.18: https://perldoc.perl.org/perl5180delta#split's-first-argument-is-more-consistently-interpreted

So added a workaround to make this work consistently on 5.16, the other option is not documenting or testing the single space string case at all. This seems potentially surprising to users using the split semantics.

@@ -49,6 +49,9 @@ sub size { length ${$_[0]} }

sub split {
my ($self, $pat, $lim) = (shift, shift, shift // 0);

# awk compatible special case on 5.16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWK.

Copy link
Member

@kraih kraih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm opposed to adding special workarounds for Perl 5.16.

@kraih
Copy link
Member

kraih commented Nov 29, 2020

@kraih
Copy link
Member

kraih commented Dec 6, 2020

A week should have been enough time for anyone who disagrees to speak up, so i'll close this PR as rejected.

@kraih kraih closed this Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants