PPIx-Regexp Perl Version Functionality

The PPIx-Regexp package provides a PPI-like parse of Perl regular expressions. Part of its functionality includes reporting on the versions of Perl under which a given regular expression or its elements are valid. Up to this point the version fumctionality has been fairly simple: method perl_version_introduced() returns the version of Perl that introduced the element, and perl_version_removed() returns the version under which it was removed, or undef if the element is valid in the most-recent Perl.

Unfortunately reality is not so constrained, and Perl 5.27.1 contains the first instance known to me of regular expression functionality which was removed and then reinstated: the un-escaped literal left curly bracket following another literal. Yes, this is just a development release, but the explanation given in perl5271delta (use of the construct in GNU Autoconf) makes it sound to me like the reinstatement needs to be taken seriously. Here is how I plan to deal with all such occurrances:

  • Method perl_version_introduced() is to be understood as returning the lowest version in which the element was introduced, if it has been introduced more than once. Note that for elements that have "always" been in Perl 5 this returns 5.000.
  • Method perl_version_removed() is to be understood as returning the highest version in which the element was removed, or undef if the element is present in the highest-published version of Perl. This is a bit awkward in the case that triggered this work, since /x{/ is fatal under what is, at this writing the highest production version of Perl (5.26.0), even though it is a warning in Perl 5.27.1.
  • New method accepts_perl( $version ) takes as its argument a Perl version number (though not, at this point, a version object) and returns a true value if it thinks that version of Perl will compile the regular expression, or a false value otherwise.
  • New method requirements_for_perl() returns a string describing the versions of Perl that will compile the regular expression. This string is for informational purposes only, and may change. Right now it looks like the Perl version information produced by eg/predump -perl.

The new methods were inspired by CPAN::Meta::Requirements. I ended up not actually using that module because it did not appear to me to support the merging of version requirements required to come up with a requirements_for_perl() for an entire regular expression. Something like structured_requirements_for_perl() (returning a data structure rather than a string) is possible, but I would rather wait to expose this until I think the structure thus exposed is reasonably stable.

The above functionality is currently only on GitHub. My current plan is to make a development release in a week or so, followed by a production release in September, which I hope will be after Perl 5.26.1. This is all subject to the feedback I get, and (maybe) whether /x{/ is fatal in 5.26.1.

Leave a comment

About Tom Wyant

user-pic Fine Perl code for over 0.005 centuries.