Add ability to limit return from line to those lines matching a regexp #284
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.