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

Add ability to limit return from line to those lines matching a regexp #284

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lbe
Copy link

@lbe lbe commented Jul 22, 2023

This pull request is a result of me recognizing that I often apply a regexp to the results returned from path->lines. The code to do this is simple so it doesn't require much effort to do. But, I continued to think of how much I would like to just specify that pattern in an argument to lines. This is very similar to the use of pattern in Path::Iterator::Rule. As such, I decide to submit a pull request that does just that.

This pull request contains the code, test and documentation additions to support filtering the return from the path->lines to only those lines matching a regexp specified in an argument name pattern (i.e. path->lines( pattern => qr/Line1/ ).

To accomplish this, I added _regexify and supporting methods from Path::Iterator::Rule. All changes to required are local to the lines, lines_raw and lines_utf8 methods.

I have modified the embedded perldoc to reflect the addition of an argument name pattern. The changes specify that the argument count will be applied before the pattern is applied.

Insofar as test are concerned, I have copied every existing test for lines and added pattern to it to insure that all test cases work properly.

If you decide that this functionality is desired, please let me know if you see any problems or want me to make any changes.

Thank you for your consideration.

Lastly, I initially wanted to add this functionality to the slurp methods. I decided to not include that in a pull request because of not being able to determine exactly how line endings should be delivered in the result. I'm open to working that in a separate pull request if you are interested.

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.

1 participant