tokuhirom's Blog

Yet another regexp stringification issue.

https://github.com/tokuhirom/p5-lingua-ja-kana/commit/43fe5a964c933b3a64373a60593450a4a231df8e
Lingua::JA::Kana doesn't work on perl 5.14+. Since it depended on regexp stringification.

This code is ugly.

        substr( $str, 0,  8, '' );    # remove '(?-xism:'
        substr( $str, -1, 1, '' );    # and ')';

Perl 5.9.5+ provides re::regexp_pattern method for this purpose. I think this code is better to fix issue.

        if ($] >= 5.009005) {
            my ($pattern, $mod) = re::regexp_pattern($str);
            $str = $pattern;
        } else {
            substr( $str, 0,  8, '' );    # remove '(?-xism:'
            substr( $str, -1, 1, '' );    # and ')';
        }

I think, we need a module named re::compat or something. But I will not write that module since this issue is not a popular issue.