Subject: | RegularExpressions::ProhibitComplexRegexes should not penalize long variable names |
This test program:
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
my $unchanged_re = qr/unchanged|stable/;
my $some_nondigit_blurb_re = qr/[a-zA-Z .,()-]{1,100}/;
my $number_re = qr/\d+[.]\d+/;
my $blurb = 'At 12.34, the number was down from 12.44 yesterday';
$blurb =~
/^At ($number_re),? $some_nondigit_blurb_re
($number_re|$unchanged_re)/o;
say "$1, was $2";
run through 'perlcritic -single-policy
RegularExpressions::ProhibitComplexRegexes' generates a warning.
This is a bit odd, because the PBP guideline says to break down a large
regexp into smaller components, and the code does just that.
However if you rename the variables to cryptic $u, $s, and $n, the code
does not trigger the warning.
perlcritic must use some heuristic to judge the 'complexity' of a
regexp, and that can never be perfect, but it needs to do more than just
count characters (which I guess it's doing at the moment) or otherwise
allow for descriptive variable names.